I have a very basic ajax call to alert the data that was reported from the server
$.ajax({ type: "POST", url: "/someform/act", //edit utl to url data: { changed: JSON.stringify(plainData) }, //edit to include success: function(data) { alert(data); //data not $data }, error: function() { //error condition code } });
According to the docs on the jquery website regarding data field on the success callback, it says that data returned is the data from the server. However for some strange reason when I alert $data
, I get [object Object]
I was expecting to see something like this, since that is what the server would send back
<status>0</status>
EDIT:
data is also passed along as the POST
Introduction to jQuery object. The jQuery object is a collection of DOM elements and behaves like a special array. Everything in jQuery is an object. When we create a new element or select an existing element the jQuery returns those elements in a collection.
To fix this, you can use the JSON. stringify() method to change the object into a string that can be popped up in the browser using the alert() method.
ajax() function returns the XMLHttpRequest object that it creates. Normally jQuery handles the creation of this object internally, but a custom function for manufacturing one can be specified using the xhr option.
You need to use JSON.stringify(data)
in the alert
to get anything readable.
Also, $data
is a completely different variable name than data
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With