Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding asynchronous service call in javascript

 
sucheta shanbhag
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you set the temp value before you make the call?

Eric
 
sucheta shanbhag
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Than you should be setting the textbox value in your callback and not where you make the Ajax call.

Eric
 
sucheta shanbhag
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic