I've done some jQuery in the past, but I am completely stuck on this. I know about the pros and cons of using synchronous ajax calls, but here it will be required.
The remote page is loaded (controlled with firebug), but no return is shown.
What should I do different to make my function to return properly?
function getRemote() {
var remote;
$.ajax({
type: "GET",
url: remote_url,
async: false,
success : function(data) {
remote = data;
}
});
return remote;
}
This question is related to
ajax
jquery
synchronous
You're using the ajax function incorrectly. Since it's synchronous it'll return the data inline like so:
var remote = $.ajax({
type: "GET",
url: remote_url,
async: false
}).responseText;
function getRemote() {
return $.ajax({
type: "GET",
url: remote_url,
async: false,
success: function (result) {
/* if result is a JSon object */
if (result.valid)
return true;
else
return false;
}
});
}
how remote is that url ? is it from the same domain ? the code looks okay
try this
$.ajaxSetup({async:false});
$.get(remote_url, function(data) { remote = data; });
// or
remote = $.get(remote_url).responseText;
Source: Stackoverflow.com