I’m calling ajax.php with jQuery. It returns a JSON response all the time.
$.ajax({
type: 'POST',
url: 'ajax.php',
data: 'some=info',
dataType: 'json',
success: function(data) {
if(data != null) {
console.log(data);
} else {
alert('IE fails here!');
}
}
});
The Ajax always returns some data in JSON format. It works fine on all browsers except IE (tested on IE 7, 8 and 9). In IE it always prints the alert (which means that it never receives the response information). Any ideas?
Update 1: I just confirmed that the post is never successful in IE, that is why data is always null.
Update 2: the post arrives but returns null only when it is IE.
Update 3 (solution): my fault, the ajax was protecting against calls from other servers. It uses an if() statement at the beginning which asks $_SERVER[‘HTTP_REFERER’]’s host be the host of the same server. Now the question would be, why doesn’t IE recognize the $_SERVER[‘HTTP_REFERER’] in the ajax call?
This is the api code (php)
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$security = parse_url($_SERVER['HTTP_REFERER']);
if(in_array($security['host'],array('localhost','tradukka.com','173.203.198.123'))) {
header('Content-type: application/json');
$array = array('nice','data','for','api');
echo json_encode($translation);
}
}
}
IE fails at the $_SERVER[‘HTTP_REFERER’] check :s
the ajax was protecting against calls from other servers. It uses an if() statement at the beginning which asks $_SERVER[‘HTTP_REFERER’]’s host be the host of the same server. the machines where i was testing on IE didn’t get the host’s name; instead it had the ip value, that is why it always threw false.