0

レイアウトメソッドを使用してCIフレームワークでテンプレートをレンダリングしています。リクエストがAJAXの場合、レイアウトのレンダリングを停止する変更をリンクのコードに追加します。

if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {

   return;

  } else {
      //render the layout (the code from example in the link)
 }

私が直面している問題は、AjaxFileUploadを使用してファイルをサーバーにアップロードしていることです。リクエストの種類は同期です。これは、レイアウトのレンダリングを意味します。応答はjSon+HTMLとして返されます。これは、レイアウト条件の通常のフローです。ファイルのアップロード時にリクエストが同期している場合、レイアウトのレンダリングを防ぐにはどうすればよいですか。

これがjsです

$.ajaxFileUpload({
url : url ",
secureuri :false,
fileElementId :'imageFile',
dataType : 'json',
type: "POST",

success : function (data)
{
  console.log(data);

},
error: function (request, status, error) { 

}
});

そしてここで私がサーバーから返すもの

 echo json_encode(array('status' => $status, 'msg' => $msg));
 return;
4

1 に答える 1

0

レイアウト変数にnullを渡すための簡単な解決策

class Welcome extends CI_Controller {

    public $layout = 'default';

    public function index()
    {
        $this->load->view('welcome_message');
    }

   public function ajax_call()
    {
        $this->layout = null;
       echo json_encode(array('status' => $status, 'msg' => $msg));
       // you can use this but your layout should be null
       $this->output
    ->set_content_type('application/json')
    ->set_output(json_encode(array('foo' => 'bar')));
    }
}
于 2013-01-08T08:11:12.307 に答える