i am sending multiple jquery ajax request from a single function one after one some from which respond and some might not is there any possible way to get the $_POST[parameters] send in specific request at request result i tried some code but end up with over writing issue
$.ajax({
url: "ajax_files/bulk_dispatch_ajax.php",
type: "POST",
data: { action:value,
trackingCode:specific_value
},
beforeSend: function() {
// counting requests
countingRequests = countingRequests+1;
},
success:function(response)
{
},
timeout: 10000,
complete: function(xhr, textStatus, tex) {
console.log(xhr);
// i want (specific_value) here in multiple request , this function is called multiple times, so prevent the
chance of overwriting
if(xhr.status != '200')
{
console.log(xhr.status);
}
}
});
as far as i know, there is no direct way to access the sent data. But you can hand it over to your callback function by your own, e.g. wrapping the callback into a own function, example:
function yourCustomAjaxFunction(data, callback) {
$.ajax({
url: getUrlFromSomewhere(),
data: data,
method: 'POST',
success: createCallback(data, callback)
});
}
function createCallback(sentData, callback) {
return function(receivedData, textStatus, jqXhr) {
if (typeof(callback) === 'function') {
callback(sentData, receivedData, textStatus, jqXhr);
}
}
}
In the example the function "yourCustomAjaxFunction" is the function mentioned ("i am sending multiple jquery ajax request from a single function"). Now you can use this as follows:
//example function which receives the sent data as well
function exampleLoggingCallback(sentData, receivedData, textStatus, jqXhr) {
console.log('Sent data: ' + sentData);
console.log('Received data: ' + receivedData);
}
//example call to your ajax function:
yourCustomAjaxFunction({foo: 'bar'}, exampleLoggingCallback);
Hope this helps.
p.S. posted examples are untested.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments