detect specific ajax request (data sent) from multiple request

Ahsan Khan

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);
                }

            }
        });
Martin Ackermann

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Referencing data sent in an AJAX request

From Dev

How to detect if GET request comes from an AJAX request or browser request?

From Dev

Headers not sent with ajax request

From Dev

Ajax request not being sent

From Dev

Detect end of ajax request from asp by javascript

From Dev

Detect end of ajax request from asp by javascript

From Dev

why is ajax request sent multiple time when I modify the html/js from the browser

From Dev

Detect ajax request call

From Dev

Detect ajax request call

From Dev

no data received from in AJAX request

From Dev

request data from php with ajax

From Dev

Sending ajax request when data sent is html data

From Dev

jQuery ajax request: how to access sent data in success function?

From Dev

No response being sent from ajax request when using require

From Dev

Multiple data used ajax request in java

From Dev

detect ajax request to normal request node js

From Dev

Posting multiple values to PHP from Ajax request

From Dev

Detect what file AJAX request is coming from in PHP

From Dev

How to read POST Request data in PHP sent from AngularJS

From Dev

Send POST request in Swift from JSON data sent over WebSocket

From Dev

How to get the data response from ajax request?

From Dev

Hot to get data from ajax request with yesod

From Dev

Ajax request to get data from php file?

From Dev

JavaScript Saving data from an ajax request

From Dev

How to get the data response from ajax request?

From Dev

Scraping JSON data from an AJAX request

From Dev

transforming JSON data returned from AJAX request

From Dev

Using data from one ajax request in another

From Dev

Getting Data from Ajax request displayed

Related Related

HotTag

Archive