Let’s say I’m sending this simple ajax request (jquery):
$.ajax({
type: 'POST',
url: '/ajax/requestForm.php',
data: {'action':'request', 'language':'sk'},
complete: function(data){
alert(data);
}
});
In my requestForm.php, I have:
<?php echo 'Hello answer!'; ?>
What alert() shows me in the browser:
[object Object]
What I want it to show:
Hello answer!
Any ideas?
Change
complete:tosuccess:and that should give you the desired result.Complete is a function to be called when the request finishes (after success and error callbacks are executed). The function gets passed two arguments: The jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object and a string categorizing the status of the request (“success”, “notmodified”, “error”, “timeout”, “abort”, or “parsererror”). That is why you are getting an object returned.