I have a HTML5 test webpage test.html
with a cache manifest. The webpage does an Ajax request to the same server, to a webpage do_get_data.php
that is listed under the section NETWORK:
in the cache manifest.
The request is performed by both Firefox 10 and iPhone iOS 5 Safari (this is logged in the serving PHP script do_get_data.php
). Firefox 10 calls the success
callback function after 10 seconds, that is, when data from the server is returned. However, my iPhone iOS 5 Safari calls the fail
callback function immediately after it started the request and doesn't call the success
callback function.
For iPhone iOS 5 Safari, the textStatus
is error
and JSON.stringify(jqXHR)
is {"readyState":0,"responseText":"","status":0,"statusText":"error"}
.
The request is performed using the following code in test.html
:
<script type="text/javascript">
function test_ok(data) {
alert('Test OK, data: ' + JSON.stringify(data));
}
function testFail(jqXHR, textStatus) {
alert(textStatus + ' | ' + JSON.stringify(jqXHR));
}
function get_data(testurl) {
var senddata, request;
alert('Request for ' + testurl + ' started.');
window.testid = new Date().getTime();
senddata = {
background: true,
requestId: window.testid
};
request = $.ajax({
url: testurl,
cache: false,
type: "GET",
data: senddata,
success: test_ok
});
request.fail(testFail);
}
</script>
<input type="button" onclick="get_data('do_get_data.php')" value="test sending" />
For reference, do_get_data.php
looks like this:
<?php
$id = md5(rand() . rand());
trigger_error(implode("\t", array('start', $id, $_SERVER['REQUEST_URI'], $_SERVER['REMOTE_ADDR'], $_SERVER['USER_AGENT']));
sleep(10);
header('Content-Type: application/json');
$json = json_encode(array('msg'=>'Test was OK'));
trigger_error(implode("\t", array('echo', $id, $json));
echo $json;
?>
jqXHR.fail()
) and the old way (success
option of$.ajax()
). Is there a particular reason for the combination? Does it yield same results whenjqXHR.done()
orerror
option respectively is used instead? – Marklanddone()
orerror
option do unfortunately not change the fact that it works in Firefox but not iOS 5 Safari. – Bascom