jquery ajax data shows [object Object]

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

Answer

alert() prints the string representation of the arguments – hence if you pass an object, you’ll get [object Object].

To inspect data, use console.log(data) better.

Leave a Reply

Your email address will not be published. Required fields are marked *