I’m having a trouble since jQuery.ajax, in this particular case, doesn’t seem to happen, so that the function always return NaN undefined as result:
function requestUploadedSearch()
{
var cookie = JSON.parse(readCookie("user_search_cookie"));
$.ajax({
dataType: "script",
async: false,
data: {
context: "search-get",
code: removeNull(cookie, cookie !== null, "code")
},
success: function(data)
{
return search_return["keywords"];
}
});
delete cookie;
}
I’ve also tried to write something like
success: function() { return "<nothing happens>"; }
But what I receive is undefined.
Please answer, I’m really freaking out with that.
Thanks in advance.
What you’re trying to do is fundamentally impossible. Your ajax operation is
asynchronous(no it isn’t durrr).Instead, re-architect your API:
Then, when you invoke it, instead of expecting a return value, pass in a function to respond to the returned data:
edit — Doh! @nickd is correct; since you’re making the call synchronously (which you really should seriously consider not doing; it’s pretty bad for your user experience) the story is different. Still, however, the approach above would work.