worked it out guys, silly me it's loading data synchronously instead
of asynchronously. Done by doing...
function test() {
var html = $.ajax({
url: "some.php",
async: false // <-- heres the key !
}).responseText;
return html;
}
:-) thanks all
On Aug 14, 1:54 pm, James Dempster <[EMAIL PROTECTED]> wrote:
> I'm looking for something that will wait inside the function until it
> has the data to return, so not the callback type system that currently
> exists.
> Something that will mimic this type of stuff will do too.
>
> e.g.
> function test() {
> $.ajax stuff here
> return data; // return data from the ajax request
>
> }
>
> var bler = test();
>
> On Aug 14, 12:08 pm, SeViR <[EMAIL PROTECTED]> wrote:
>
> > 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