I have an AJAX call:
$('#testyo').click(function(){
$.ajax({
type: 'GET',
url: "../messages/drew",
dataType: 'JSON',
success:function(data){
alert(data);
},
error: function(data)
{
console.log(data);
alert("Error: "+data);
}
});
return false;
});
It should be successful, but I get the alert("Error: "+data) alert. The data is [object Object]. So the alert just says Error: [object Object]
In my console.log(data)
Object {readyState: 4,
getResponseHeader: function,
getAllResponseHeaders: function,
setRequestHeader: function,
overrideMimeType: function…}
abort: function ( statusText ) {always: function () {complete: function () {done: function () {error: function () {fail: function () {getAllResponseHeaders: function () {getResponseHeader: function ( key ) {overrideMimeType: function ( type ) {pipe: function ( /* fnDone, fnFail, fnProgress */ ) {progress: function () {promise: function ( obj ) {readyState: 4responseText: "drew"setRequestHeader: function ( name, value ) {arguments: nullcaller: nulllength: 2name: ""prototype: Object__proto__: function Empty() {}<function scope>state: function () {status: 200statusCode: function ( map ) {statusText: "OK"success: function () {arguments: nullcaller: nulllength: 0name: ""prototype: Object__proto__: function Empty() {}<function scope>then: function ( /* fnDone, fnFail, fnProgress */ ) {__proto__: Object
As you can see it does show the responseText: "drew" which is what I want. I'm just curious to know why is passing through my fail function, and not my success. Please let me know if there is anything else you would need to help me solve this.