My question is there is a way to define timeout for each parallel ajax post when we used jquery deffered interface. E.g.
parallelPost: function(toUrl1, toUrl2, theData1, theData2, contentType, dataType, successHandler, errorHandelr, completeHandler) {
$.when($.ajax(this.createAjaxCall(toUrl1, theData1, true, headers, 'POST', contentType, dataType,1000)),
$.ajax(this.createAjaxCall(toUrl2, theData2, true, headers, 'POST', contentType, dataType,2000))).done(function(res1, res2) {
successHandler(res1, res2);
}, errorHandelr, completeHandler);
},
createAjaxCall: function(toUrl, theData, isAsync, headers, verb, contentType, dataType, timeout, successHandler, errorHandelr, completeHandler) {
return {
url: toUrl,
cache: false,
type: verb,
data: theData,
dataType: dataType,
timeout: timeout || 0,
async: isAsync,
headers: headers,
contentType: contentType ? contentType : 'application/x-www-form-urlencoded',
success: successHandler,
error: errorHandelr,
complete: completeHandler
};
}
The timeouts for each parallel posts were defined 1000 and 2000. My goal to get those responses that were succeeded in defined timeouts. Thus, when the first request was time-outed and second was not, then return only second response.
Via jquery deffered interface if at least one is time-outed fail callback is called.
Is there is a way to define such behavior or may be another interface that provide solution to issue