Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.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
如何将php json响应返回到ajax查询_Php_Jquery_Json_Ajax_Cordova - Fatal编程技术网

如何将php json响应返回到ajax查询

如何将php json响应返回到ajax查询,php,jquery,json,ajax,cordova,Php,Jquery,Json,Ajax,Cordova,我有一个cordova应用程序向php发出ajax请求。我想首先返回json响应,然后继续处理。在Ubuntu终端中,它可以工作。然而,在应用程序中,它显示404 流动的 $.ajax({ url: 'http://192.168.0.104/ajaxurl', type: 'post', dataType: 'json', data: {"test":"data"}, success: function(data) { }, error:

我有一个cordova应用程序向php发出ajax请求。我想首先返回json响应,然后继续处理。在Ubuntu终端中,它可以工作。然而,在应用程序中,它显示404

流动的

$.ajax({
    url: 'http://192.168.0.104/ajaxurl',
    type: 'post',
    dataType: 'json',
    data: {"test":"data"},
    success: function(data) {
    },
    error: function(error) {
    // here return 404
    }
});
PHP


我在网上找不到任何东西,可能也不确定要搜索什么。有人知道什么吗?

请参见
数据:{“test”:“data},
行中双引号处的语法错误
数据:{“test”:“data”},
行中缺少双引号。php代码中对header()的调用应该在任何
echo
语句之前。我假设您的php脚本在被访问时会发送错误。您可以检查浏览器开发工具中的网络选项卡来监视服务器请求和响应。对不起,“是一个输入错误。在Ubuntu终端中,它可以工作。例如,在终端中,我可以看到{”结果“:“success”}root如果您使用iOS,您应该使用https。例如,您可以回显您需要的内容,并在单独的后台进程中运行其余的代码,php为此提供了
exec
函数。在ajax完成之前,您无法获得xhr的结果,而在服务器这样做之前,xhr是不完整的。
ignore_user_abort(true);
set_time_limit(0);
ob_start();
echo json_encode($res);
header('Connection: close');
header('Content-Length: '.ob_get_length());
ob_end_flush();
ob_flush();
flush();
// continue processing