I have an AJAX request of datatype JSON which sends data and receives JSON encoded data from PHP.
Sometimes it works and sometimes it does not. In developers tool(chrome) it shows text/html
but shows application/json
when added header('Content Type: application/json')
.
My question is why I have to use a header in chrome but not in firefox (in firefox it works fine)?
Another problem is that my AJAX requests are called on after another in firefox they work fine but in chrome it just runs once! Why?
function abc(){
$.post('url.php',{ x : x },function(data){
//my stuff
setTimeout(abc,5000);
},'json');
}
in php
<?php
header('Content Type : application/json');
//this not required in firefox.
echo json_encode(array("abc"=>$abc));
?>