and just to note success = SaveSearch_Success,
should look just like that... it shouldn't be success = SaveSearch_Success(), or success = SaveSearch_Success(data), or *anything else*... it already "knows" to pass the resultant JSON to the function 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.