I’m having a nightmare trying to do this.
I must have tried about 15 different methods so far from different posts I’ve read but all have failed.
I am just trying to get a return value from an ajax post.
Here is my code
var test = compareNew(this.name, "remove");
alert(test);
function compareNew(obj, action) {
$.ajax({
url: "AJAX_compare_server.php",
type: 'post',
data: {
compare_id: obj,
action: action
},
success: function (result) {
var myObject = eval("(" + result + ")");
alert(myObject.html);
return(result);
}
});
}
The alert(myObject.html); correctly shows me the html returned but the alert(test); shows me ‘undefined’.
I’ve spent hours on this but can’t figure it out.
Can you see what I’m missing?
Actually
returnwon’t work in anasynchronouscall but if you setasync:falsethen it’ll work, in this (synchronous call) case you may try thisAlso you can use it like
And call it like