PHP Jquery的Ajax调用抛出网:: ERR_EMPTY_RESPONSE [英] PHP Jquery Ajax call throws net::ERR_EMPTY_RESPONSE

查看:2139
本文介绍了PHP Jquery的Ajax调用抛出网:: ERR_EMPTY_RESPONSE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的JavaScript code在页​​面中。当AJAX调用时,我可以看到浏览器检查/调试器部分抛出的网:: ERR_EMPTY_RESPONSE 错误。它工作正常,在本地主机环境中,但会引发上述错误的产生。

I have the following JavaScript code in the page. When the ajax call is made, I could see that the browser inspect/debugger section throws net::ERR_EMPTY_RESPONSE error. It works fine in localhost environment but throws above error in production.

在客户端code,

<script>
$(document).ready(function(){
    $("#identityLinks a").on("click", function(){
    value = $(this).attr("id");
    if(value != "")
    {
        $.ajax({
            url:  "publish/updateUsersData.php",
            type: "POST",
            data: {receiverId: value},
            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            dataType: "json",
            success: function(data) {
              //alert(data["result"]);
              console.log(data["result"]);
            },
            error: function(xhr, textStatus, errorThrown) {
               //alert(xhr +" "+ textStatus +" "+errorThrown);
               console.log(xhr +" "+ textStatus);
            }
        });
    }
    });
</script>

在服务器端code(PHP),我有以下code中的 updateUsersData.php

In Server-side code (PHP), I have the following code in updateUsersData.php:

<?php
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 01 Jan 1996 00:00:00 GMT');
header('Content-type: application/json; charset=UTF-8');
if(isset($_POST["receiverId"]))
{
    $receiver_id = trim($_POST["receiverId"]);
    $arr = array("result"=>$receiver_id);
    echo json_encode($arr); die();
    break;
}
else
{
    $arr = array("result"=>"No user data received. Error!");
    echo json_encode($arr); die();
    break;
}
?>

你认为这是由于标头过期jQuery的1.9.1版本来电或一个错误?我没有发现这样的错误,当我们为previous版本。此外,该code还未只是前一段时间更新了5个月和浏览器错误蠕变。感谢您的帮助和支持。

Do you think it's due to header with Expire calls or a bug in Jquery 1.9.1 version? I didn't find such errors when we were previous versions. Also, this code has not been updated for 5 months and browser errors creep just some time ago. Thanks for all your help and support.

编辑:

状态:此的问题未得到解决为止。 jQuery的AJAX 专家的帮助需要。任何人,请促进这个问题。此外, CORS 不负责这个问题。

Status : This ISSUE is not resolved so far. Jquery AJAX experts' help needed. Anyone, please promote this question. Also, CORS is not responsible for this issue.

当发生上述错误,我被直接带到这一行

When clicking on the console in which the above error occurred, I was directly taken to this line in

JQuery 1.9.1 where console error lines point to:

=> xhr.send( ( s.hasContent && s.data ) || null );

Also these ones are shown in console error mark:

=> transport.send( requestHeaders, done );

=> ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle 
   || handleObj.handler )
  .apply( matched.elem, args );

=> return typeof jQuery !== core_strundefined && 
(!e || jQuery.event.triggered !== e.type) ?
jQuery.event.dispatch.apply( eventHandle.elem, arguments ) : undefined;

负责这个临时接针jQuery的最新版本显示错误。

Is jquery latest version responsible for this PROVISIONAL HEADERS ARE SHOWN error.

推荐答案

我相信,你的要求是不归类为一个简单的请求的CORS规范下的:

I believe your request is not classed as a "simple request" under the CORS specification:

http://www.w3.org/TR / CORS /#简单跨域请求-0

因为你设置一个响应标头的Content-Type:应用/ JSON

since you are setting a response header for Content-Type: application/json.

所以,你的服务器将需要处理的preflight要求,其中包括设置在请求和响应一些额外的标头的CORS请求是成功的。

So your server will need to handle the preflight request, which involves setting some additional headers on both the request and response for the CORS request to be successful

下面是你需要做的好文章 - 在没那么简单检查出位:

Here is a good article on what you need to do - check out the bit under "not so simple":

http://www.html5rocks.com/en/tutorials/cors/

这篇关于PHP Jquery的Ajax调用抛出网:: ERR_EMPTY_RESPONSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆