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.
In client side 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>
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;
}
?>
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.
Edit:
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;
Is jquery latest version responsible for this PROVISIONAL HEADERS ARE SHOWN error.
I believe your request is not classed as a "simple request" under the CORS specification:
http://www.w3.org/TR/cors/#simple-cross-origin-request-0
since you are setting a response header for Content-Type: application/json.
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/
So this can happen for a number of reasons regardless of language or technology being used. I have encountered this with extremely small payloads of 15-20 data points being sent back and forth using angular resource. PHP, Jquery, Angular all handle the error differently but the results down to one of three things happening.
Latency or Network issues, I have had this happen on extremely slow connections, again this could be anything to a bad router or improper firewall configuration to just on a crappy network, to programs like avast that put a proxy in place to protect you from viruses.
High server load, I have forced a server to be at 100% cpu from stress testing and this will happening on random calls because the server is not handing the requests fast enough. This is hard to fix and really is a scaling issue for the system.
Huge Data Sets, large items being sent that the response fails, usually this can be fixed by adjusting your timeout settings on whatever web server you are using.
I have same problem on my page sometimes. I think this happens because of number of variables or how big they are. I have a page that sends a json of about 250 variables without any problem, but this error occurs in this page while about 1500 variables are to be sent. This problem is new. Every thing even with 3000 variables were without problem, before. This problem occurs for me both in chrome and firefox in recent versions. It's not server side error because I have configured apache to revive 1 million variables of 30 Mb data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With