0

I am calling an ajax call , in which providing an array with data, when I am going to debug this code in console in shows me data is undefined why ?

Mangrio
  • 1,000
  • 19
  • 41

1 Answers1

1

In the success function of your first ajax call, you have this:

success: function (response) {
    orderId = data;
    if (data != null) {
        orderStatus = "Order has been placed successfully.";
    }
}

Note that you've called the argument to the callback response, but then used data. The code as quoted should fail with a ReferenceError, because there's no data in scope in that callback (the only place you have var data is inside another callback). I assume you have it declared in code you haven't quoted.

I assume you meant response, not data:

success: function (response) {
    orderId = response;
    if (response != null) {
        orderStatus = "Order has been placed successfully.";
    }
}
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • you are right. I need my order to be successful ? how would I do that – Mangrio Aug 19 '16 at 08:02
  • should I declare `var data` at the top? – Mangrio Aug 19 '16 at 08:06
  • 1
    @QadeerMangrio: No, you should do what I showed you in the answer. The code's pretty unclear, but you may also need to [read this question's answers](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call). – T.J. Crowder Aug 19 '16 at 08:06