the code i posted should have no problem working as long as it is used
properly... without seeing your actual HTML and where stuff is and
what gets called, it's impossible to help completely.....  and the
<body>/<head> thing won't matter that much as long as document.ready
is used...  but even that's a guess without seeing what is really
going on with the HTML


On Aug 20, 9:34 am, dkomo872 <dkomo...@comcast.net> wrote:
> On Aug 20, 7:01 am, Leonard Martin <leonard.mar...@gmail.com> wrote:
>
>
>
> > The trouble is that the $.post is run asynchronously so anything after
> > the $.post will be executed before the callback function.
>
> > If you want the returned data to be available outside the callback
> > then it will have to be inside a function which is called from within
> > your callback method.
>
> > e.g.
>
> >  var data1;
>
> >     $.post('save_search.php', formData, function(data) {
>
> >          data1 = data;
> >          handle();
>
> >        } );
> > function handle() {
> >     jsonData = eval('(' + data1 + ')');
>
> >     if (jsonData.return_status.search("successful") > -1)
> >       $('#msg_div').html("<font color=red>Search was saved</font>");
> >     else
> >       $('#msg_div').html("<font color=red>Search was not saved. Try
> > saving again.</font>");
>
> > }
>
> Sadly, I talready ried this and hit what appears to be another
> problem.   "handle()" (or my equivalent function) came up as undefined
> according to Firebug when I tried to call it inside the callback
> function.
>
> It may be because my Javascript code is within the <body> of the HTML
> file (due to reasons out of my control) rather than the <head>.  Maybe
> I can't use functions this way inside <body>.  Or maybe it's same old
> asynchronous problem with Ajax.

Reply via email to