aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Regarding asynchronous service call in javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Regarding asynchronous service call in javascript" Watch "Regarding asynchronous service call in javascript" New topic
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: 15376
    
    6
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: 15376
    
    6
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: 15376
    
    6
http://radio.javaranch.com/pascarello/2006/07/07/1152292250518.html

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding asynchronous service call in javascript