我有一个AJAX调用:的Javascript AJAX返回错误
$('#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;
});
它应该是成功的,但我得到的警报( “错误:” +数据)警报。数据是[对象对象]。因此警报只是说错误:[对象的对象]
在我的console.log(数据)
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
正如你可以看到它确实表明了responseText的:“画”,这是我想要的。我只是想知道为什么要通过我的失败功能,而不是我的成功。请让我知道是否还有其他需要帮助我解决的问题。
使用'console.log'在javascript控制台中打印错误并检查您的对象。 – Alvaro 2014-09-04 13:57:09
这不是我所做的吗? – user3591126 2014-09-04 13:59:41
收到的HTTP代码是什么? – Fractaliste 2014-09-04 14:01:27