KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I built a test case of an ajax call (jQuery 1.6.2) that looks like: jQuery( document ).ready( function( $ ) { var test = function( x ) { $.ajax({ url: 'http://www.someotherdomain.com/test.php', data: { x: x }, dataType: 'jsonp', crossDomain: true, success: function( data ) { console.log( data.name ); }, error: function() { x++; test( x ); } }); }; test( 1 ); }); And the corresponding test.php file looks like: if ( 5 > $_GET[ 'x' ] ) { header('HTTP/1.1 503 Service Temporarily Unavailable'); die(); } else { header( 'content-type: application/x-javascript' ); echo $_GET[ 'callback' ] . '({"name":"Morgan"})'; } Even though the jQuery documentation indicates that the error handler for jsonp calls is never fired, this script works just as I intended. It makes four "unsuccessful" calls to test.php which return 503 errors, and then test() recursively calls itself incrementing x until the ajax call is "successful" and the data is output to the console. So my test case above works, but my actual code doesn't work, which looks more like the following: jQuery( document ).ready( function( $ ) { var completed = 0; var fiftystates; // assume an array of state objects var updateState = function( index, state ) { var d = index % 5; // for subdomains sub0, sub1, sub2, sub3, sub4 $.ajax({ url: 'http://sub' + d + '.mydomain.com/update_state.php', data: { state: state.id }, dataType: 'jsonp', crossDomain: true, success: function() { completed++; var complete_percent = completed / fiftystates.length * 100;
Tags (comma-separated)
Save Edits
Cancel