i have javascript function in which i made ajax call with jquery. My problem is the response of ajax is not received but the next statements in javascript runs
I know about the success event of the jquery ajax. but here is the problem
on clicking the submit button
it returns me "undefined" because alert in the end is executed before the ajax response
Hi Ramandeep,
"success" is a callback function that is executed when you receive successful response for your AJAX request. I assume that you understand this as you have mentioned it in your post.
In this case Javascript will execute the "alert" statement in your code. This is normal behaviour.
May be answer to the question below will help us to resolve your issue -
Can you tell us the requirement to put that "alert" statement? I think it is just a debug mechanism that you may have implemented.
Hello,
As Bear has mentioned there are two alerts. I assumed that you are talking about second one.
Even there you are not accessing any Javascript object. I think you are getting "undefined" from some other statement probably and not the alert.
Hello,
You may need to check if you are getting expected values for the data that is being passed to the Ajax endpoint.
As there are places where you are accessing property of an object accessed using jQuery, they can throw "undefined" in case the JS object is not present.
Regards,
amit
My pie came with a little toothpic holding up this tiny ad:
a bit of art, as a gift, that will fit in a stocking