Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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
Ajax响应在响应页面中显示php文本_Php_Jquery_Ajax_Codeigniter - Fatal编程技术网

Ajax响应在响应页面中显示php文本

Ajax响应在响应页面中显示php文本,php,jquery,ajax,codeigniter,Php,Jquery,Ajax,Codeigniter,这是我的视图文件中的ajax代码 $('#bidck').click(function (e) { e.preventDefault(); var data = "ajax=ajax"; $.ajax({ type: 'POST', url: 'http://localhost:8080/test/check', data: data, success: function (data) {

这是我的视图文件中的ajax代码

$('#bidck').click(function (e) {
    e.preventDefault();
    var data = "ajax=ajax";
    $.ajax({
        type: 'POST',
        url: 'http://localhost:8080/test/check',
        data: data,
        success: function (data) {
            console.log(data);
        }
    });
})
代码运行良好,这方面没有问题,但响应端有问题,这是我的控制器端

<?php defined('BASEPATH') OR exit('No direct script access allowed');

 class test extends CI_Controller
 {

public function check()
{
    $data = array("data" => "true", "m" => "message");
    Header('Content-Type: application/json');
    echo json_encode($data);
}
}
您不见了

数据类型:“json”

您可以在之后添加这一行

数据:数据


扩展为使用CI_控制器的类必须始终将第一个字母大写

在您的情况下:您需要将test更改为test,并确保文件名相同(test.php



尝试删除“标题('Content-Type:application/json');”删除了标题('Content-Type:application/json');如果你真的看到
你的文件是以
开头的吗?不,这是我的第一行,伙计们,我在浏览器中查看了直接链接,它也显示了这样的内容,所以它不是一个jquery问题可能是编码方面的一些问题好的,在echo json_encode之前试试这个,以显示错误,我会将它添加到答案中,它不会显示出来未定义的变量:jsonOUTPUT:
if ($json === false) {
    // Avoid echo of empty string (which is invalid JSON), and
    // JSONify the error message instead:
    $json = json_encode(array("jsonError", json_last_error_msg()));
    if ($json === false) {
        // This should not happen, but we go all the way now:
        $json = '{"jsonError": "unknown"}';
    }
    // Set HTTP response status code to: 500 - Internal Server Error
    http_response_code(500);
}
echo $json;
<?php defined('BASEPATH') OR exit('No direct script access allowed');
 class Test extends CI_Controller
 {
  public function check()
  {
   $data = array("data" => "true", "m" => "message");
   Header('Content-Type: application/json');
   echo json_encode($data);
  }
 }
?>