Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将响应传递给返回的变量——Jquery_Jquery_Ajax_Json_Codeigniter - Fatal编程技术网

将响应传递给返回的变量——Jquery

将响应传递给返回的变量——Jquery,jquery,ajax,json,codeigniter,Jquery,Ajax,Json,Codeigniter,我试图在jquery中创建一个用户函数,通过codeigniter控制器打印消息……以下是我的代码: 编码点火器 public function aj_lang_print(){ foreach ($_POST as $post){ $arr = json_decode($post); } if (empty($arr) or !$_POST){ echo 'no-post'; }else{

我试图在jquery中创建一个用户函数,通过codeigniter控制器打印消息……以下是我的代码:

编码点火器

public function aj_lang_print(){
    foreach ($_POST as $post){
        $arr = json_decode($post);
    }
    if (empty($arr) or !$_POST){
        echo 'no-post';
    }else{                          
            $lang_file = $arr->langFile;
            $lang_str = $arr->langStr;
            $msg = array(
                    'msg' => $this->lang_model->langpout($lang_file, $lang_str)
                    );
            echo json_encode($msg);

    }
Jquery

    function langPrint(langFile, langStr){
    var arr = {
                'langFile': langFile,
                'langStr' : langStr
                };
    $.ajax({
       url: 'ajaxparser/aj_lang_print',
       type: 'POST',
       data: {data: JSON.stringify(arr)},   
       dataType: 'json',
       success: function(response){
              return $.parseJSON(response);
        //alert($.parseJSON(response));         
       }    
    });
}
问题是响应值为NULL,尽管Firebug正确调试响应->“{'msg'=>'value'}”。。。 所以jquery正确地发布,然后控制器获得发布的数据,并通过模型正确地查询数据库,并正确地发回json编码的数据。。。 我想问题在于成功的功能


你知道吗?

因为这是一个异步调用,你不能只返回数据。这仅在async设置为false时才起作用。您需要处理成功句柄中的数据,尽管它应该收到响应警报,不是吗?因为我得到空值作为一个警报…是的,它应该。因此,我将重点介绍生成jsonI的codeigniter部分。我不认为在已经将数据类型定义为JSON的情况下不需要解析JSON。试试这个:警报(响应);警报(response.msg);thanx jammypeach。。。至少现在我得到了正确的警告。。。