I have met some problem with jQuery ajax() in Safari, so I created some simple code to test.
A request is sent to PHP file and after 10 seconds, in all other browsers, it get "returned data" and alert "succeeded" then "completed"; but in Safari, it alert "error" and "completed", and can get no data.
If just change the 10 seconds to 9 (sleep(9);), it will also work in Safari. So why is 10 seconds a critical point for Safari? How to make Safari functions well like other browsers for ajax()?
This is the HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#submit").click(function () {
$.ajax({
async: false,
cache: false,
type: "POST",
timeout: 10000,
url: "processor.php",
dataType: "json",
success: function (data) {
$("#status").html(data);
alert('succeeded');
},
error: function (request, status, error) {
alert('error');
},
complete: function () {
alert('completed')
}
});
return false;
});
});
</script>
</head>
<body>
<div>
<input id="submit" type="button" value="send request" />
</div>
<div id="status"></div>
</body>
</html>
And this is the PHP code:
<?php
sleep(10);
echo json_encode("Returned Data");
?>
Your help will be greatly appreciated, Sean Liu