JQuery $ajax() Problem
JQuery $ajax() Problem
Hello,
I have a problem with the $ajax() function.
My function looks like so:
- $.fn.addBooking = function(booking) {
var booking_json = JSON.stringify(booking);
- var result;
$.ajax({
type: 'POST',
url: 'http://localhost/myurl.php',
data: {username: "myuser",
password: 'mypassword',
mode: "myMode",
format: "json",
data: booking_json },
dataType: 'json',
success: function(data, textStatus, jqXHR) {
result = data[0].status;
},
error: function(jqXHR, textStatus, errorThrown) {
alert('ERROR '+errorThrown);
result = 'false';
}
});
return result; //always undefined
}
But when I call this function the return value is alwas undefined, although the success function is called.
Can somebody help me plz?
Best regards
mc