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 ?
            Asked
            
        
        
            Active
            
        
            Viewed 51 times
        
    0
            
            
         
    
    
        Mangrio
        
- 1,000
- 19
- 41
- 
                    I'm surprised it's running at all, that code tries to read the value of an undeclared symbol. You must have a `var data` somewhere you're not showing. – T.J. Crowder Aug 19 '16 at 07:58
- 
                    data is declared above – Mangrio Aug 19 '16 at 07:59
- 
                    Not in the scope it's used it isn't. – T.J. Crowder Aug 19 '16 at 07:59
- 
                    so how do I do that? – Mangrio Aug 19 '16 at 08:00
1 Answers
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
- 
                    
- 
                    
- 
                    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