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 t
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 server send a JSON, you need to put dataType: 'json'
to your ajax call. Be aware there's some mistake in your ajax call.
$.ajax({
type: "POST",
url: "/someform/act", // NOT 'UTL',
data: {
key: value,
key2: value2
},
// or data: plaindata, // If 'plaindata' is an object.
dataType: 'json',
success: function(data) {
console.log(data); // As moonwave99 said
},
error: function() {
//error condition code
}
});
EDIT
When sending data, you should send an object. jQuery will handle the array to sned it to the server. So if plain data is an object, it should be like this
data: plainData,
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.