| Author |
Jquery ajax issue
|
RamandeepS Singh
Ranch Hand
Joined: Aug 25, 2009
Posts: 60
|
|
HI
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
PLEASE HELP ME!!!
Thanks
Ramandeep S
|
 |
amit punekar
Ranch Hand
Joined: May 14, 2004
Posts: 491
|
|
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.
regards,
Amit
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56554
|
|
Which alert? There are two.
And yes, code after the Ajax call will execute before the Ajax call finish. That's the asynchronous part.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
RamandeepS Singh
Ranch Hand
Joined: Aug 25, 2009
Posts: 60
|
|
First of all
Thanks
Is there any way out.. to handle this..??
yes that was debugging alert.
Its returning me undefined
Thanks & Regards
Ramandeep SIngh
|
 |
amit punekar
Ranch Hand
Joined: May 14, 2004
Posts: 491
|
|
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.
regards,
Amit
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15362
|
|
The Ajax call is asynchronous. It goes out to the server and than the rest of your code continues on its way.
You are acting like it is synchronous.
Eric
|
 |
RamandeepS Singh
Ranch Hand
Joined: Aug 25, 2009
Posts: 60
|
|
Thanks to ALL for your reply
Forget about the alerts...
it was returning me undefined because ajax response takes some time
But know i used SJAX
http://www.hunlock.com/blogs/Snippets:_Synchronous_AJAX
Your Help is highly appricaited
Thanks
Ramandeep SIngh
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15362
|
|
RamandeepS Singh wrote:
it was returning me undefined because ajax response takes some time
It is not because it takes time to get back, it is because the call is asynchronous.
Using Synchronous calls can lead to browsers locking up.
Eric
|
 |
RamandeepS Singh
Ranch Hand
Joined: Aug 25, 2009
Posts: 60
|
|
Eric Pascarello wrote:
RamandeepS Singh wrote:
it was returning me undefined because ajax response takes some time
It is not because it takes time to get back, it is because the call is asynchronous.
Using Synchronous calls can lead to browsers locking up.
Eric
Eric i understand thats async.. that why next statments execute..
Ok so what should i do instead of sync request...
By Browser locking you mean for sometime?? Till the response?
Thanks & Regards
Ramandeep Singh
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56554
|
|
|
Why block? Use the success callback to perform any operations that need to wait for the response.
|
 |
RamandeepS Singh
Ranch Hand
Joined: Aug 25, 2009
Posts: 60
|
|
Bear Bibeault wrote:Why block? Use the success callback to perform any operations that need to wait for the response.
Its returning me undefined... please look the above script i poted.. i used callback
but it was returning me as of async request
Thanks
Ramandeep S
|
 |
amit punekar
Ranch Hand
Joined: May 14, 2004
Posts: 491
|
|
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
|
 |
 |
|
|
subject: Jquery ajax issue
|
|
|