Wednesday, 17 May 2017

How to get request details from $.ajax response?

I am working on Node.js App. Its a simple app which hits a single url multiple times with different POST params.

As Node is Async and Eventdriven, the response from server is not coming in the request sequence and I cant identify that which response has came from which request.

How can we overcome this problem? Does this object jqXHR can help?

$.ajax({//request code}).done(function (data, textStatus, jqXHR) {//get Requested POST param}

Node js code is as follow.

i = 0;
    for(monthNo = startMonth ; monthNo <= endMonth ; monthNo++){    

             jsdom.env(
             '',
              ["http://code.jquery.com/jquery.js"],
              function (errors, window) {
                var $ = window.jQuery;
                shouldStart = true;
                var data = allInputData[i];
                i++;

              $.ajax({
                        contentType: "application/json; charset=utf-8",
                        data: JSON.stringify(data),
                        dataType: "json",
                        type: "POST",
                        url: urlcal
                    }).done(function (data, textStatus, jqXHR) {       }  
    }



via Hemal Pandya

No comments:

Post a Comment