njc njc - 2 months ago 5
Ajax Question

duplicate $.ajax request does not fire callback

If I make the exact same ajax request in the callback from the first request, the callback for the second request does not fire.

function doCall(){
console.log('1');
$.ajax(
'InfoRequest.cgi?reqType=rxChanNames&deviceName=Ultimo-0700b9'
)
.always(function(d){
console.log('success1');
$.ajax(
'InfoRequest.cgi?reqType=rxChanNames&deviceName=Ultimo-0700b9'
)
.always(function(d2){
console.log('success2');
});
});
}


The second call is made, and a 200 responds from the server but 'success2' is never printed.
The response for the request is JSON:

{"data":[],"status":"wserrortimeout"}


If I change the second request to

'InfoRequest.cgi?reqType=rxChanNames&deviceName=Ultimo-0700b8'


then it fires the callback.

Before anyone asks why I want to do this, what I have outlined here is a much simplified version of what I am actually doing that still demonstrates the problem. The application is on embedded hardware which sometimes responds with an error in which case the request needs to be retried.

Thanks in advance for any suggestions.

Answer

The fact that changing a parameter makes the call work leads me to believe it's a cache issue.

Use cache:false in the ajax parameters to prevent caching.