| Author |
Regarding asynchronous service call in javascript
|
sucheta shanbhag
Greenhorn
Joined: Sep 28, 2007
Posts: 18
|
|
Hi All,
I am facing this issue where in there are 2 functions say
var temp;
function A(){
B();
//set the temp variable value in a textfield.
}
function B(){
//service call through dynamic script node (aynchronous call)
//this call returns a JSON object.
}
function callback(){
//callback function for the service call..
temp= //retrieve required value from the returned JSON object and set in the temp variable.
}
Now this code works well most of the times,
But sometimes before the asynchronous service call is completed..the 'temp'value is set in the textbox..which is rendered blank.
So my question is how can I know that the service call is completed,so that only then I will set the retuned value in the textbox?
Thanks.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15362
|
|
Why don't you set the temp value before you make the call?
Eric
|
 |
sucheta shanbhag
Greenhorn
Joined: Sep 28, 2007
Posts: 18
|
|
|
Because the temp variable is set as per the value returned by the service call,whcih I then set to the textfield.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15362
|
|
Than you should be setting the textbox value in your callback and not where you make the Ajax call.
Eric
|
 |
sucheta shanbhag
Greenhorn
Joined: Sep 28, 2007
Posts: 18
|
|
Actually this is not an AJAX call.
this is a service call by dynamic svript node generation.
wherein you hit an URL,and get a JSON object(in this case ) as the response.
Like in AJAX, we check tht when the response.status is 200, and later process the results
In the same way I wanted to find out whether we can do the same thing with asynchronous service call..?
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15362
|
|
http://radio.javaranch.com/pascarello/2006/07/07/1152292250518.html
Eric
|
 |
 |
|
|
subject: Regarding asynchronous service call in javascript
|
|
|