James Dempster escribió:
Is it possible to make a function that returns a value from an ajax
request. I want the javascript execution to stop until the function
returns it's value. Inside the function it makes it's ajax request
then returns a value based on the data returned. Currently I only see
that a callback function is called.


You can return HTML or JSON, I prefer JSON:
your server response:
{stat: "ERROR", msg:"Problem with the database."}

JavaScript:
$.post("url", {data}, function(json){
   data = eval("("+json+")");

   if(data.stat == "ERROR"){
      alert(data.msg);
   }
});

This function wait the server response, and run the code when the
data is back.

--
Best Regards,
José Francisco Rives Lirola <sevir1ATgmail.com>

SeViR CW · Computer Design
http://www.sevir.org
Murcia - Spain

Reply via email to