I have an HTML5 test web page test.html with a cache manifest. The web page executes an Ajax request to the same server, to the do_get_data.php web page specified in the NETWORK: section NETWORK: in the cache manifest.
The request is executed by both Firefox 10 and iPhone iOS 5 Safari (it is registered in the do_get_data.php script serving PHP). Firefox 10 calls the success callback in 10 seconds, that is, when returning data from the server. However, my iPhone iOS 5 Safari calls the fail callback function immediately after starting the request and does not call the success callback function.
On iPhone Safari iOS 5, textStatus has error and JSON.stringify(jqXHR) has {"readyState":0,"responseText":"","status":0,"statusText":"error"} .
The request is executed 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; ?>