Imagine I run this:
$.ajax({
type: 'POST',
url: '/ajax/watch.php',
data: {'watch':'aukcia', 'id':aukciaID},
complete: function(responseText){
alert(responseText);
}
});
Inside /ajax/watch.php, let’s say I have this:
echo 'this is what I want';
And the alert(responseText) returns:
[object Object]
Instead of my text string that I need.
Any help, please?
Looks like somehow your jQuery is returning the XMLHttpRequest object, instead of your response.
If that is the case, you should ask for its
responseTextproperty, like this:However, if that does not work, you might be actually receiving a JSON response, and the
[object Object]you are seeing might be your browser’s representation of your JSON response.You should be able to inspect its contents by navigating around the object properties. However, if you want, you can also tell jQuery not to parse your JSON response, by including
dataType: 'text'on your call:For more information, see: http://api.jquery.com/jQuery.ajax/