繁体   English   中英

jQuery Ajax失败

[英]jQuery ajax fail

var url = 'http://localhost:3000/categories/?callback=?';

    $.ajax({
        type: 'GET',
        url: url,
        jsonpCallback: 'jsonCallback',
        contentType: "application/json",
        cache: true,
        dataType: 'jsonp',
        success: function(data) {
           console.log(data);
        },
        error: function(e) {
           console.log(e);
        }
    });

控制台日志错误:

index.html:25对象{readyState:4,getResponseHeader:函数,getAllResponseHeaders:函数,setRequestHeader:函数,overrideMimeType:函数…}中止:函数(a){var b = a || u;返回c && c.abort(b) ,x(0,b),此}始终:函数(){返回e.done(参数)。失败(参数),此}完成:函数(){if(h){var c = h.length ;!函数g(b){n.each(b,function(b,c){var d = n.type(c);“ function” === d?a.unique && k.has(c)|| h.push (c):c && c.length &&“ string”!== d && g(c)})}(参数),d?f = h.length:b &&(e = c,j(b))}返回此} done:函数(){if(h){var c = h.length;!function g(b){n.each(b,function(b,c){var d = n.type(c);“ function” == = d?a.unique && k.has(c)|| h.push(c):c && c.length &&“ string”!== d && g(c)})}(参数),d?f = h.length:b &&( e = c,j(b))}返回此错误:function(){if(h){var c = h.length;!function g(b){n.each(b,function(b,c) {var d = n.type(c);“ function” === d?a.unique && k.has(c)|| h.push(c):c && c.length &&“ string”!== d && g(c)} )}(参数),d?f = h.length:b &&(e = c,j(b))}返回此}失败:function(){if(h){var c = h.length; 函数g(b){n.each(b,function(b,c){var d = n.type(c);“ function” === d?a.unique && k.has(c)|| h。 push(c):c && c.length &&“ string”!== d && g(c)})}(参数),d?f = h.length:b &&(e = c,j(b))}返回此} getAllResponseHeaders:函数(){返回2 === t?e:null} getResponseHeader:函数(a){var b; if(2 === t){if(!f){f = {}; while(b = gb .exec(e))f [b [1] .toLowerCase()] = b [2]} b = f [a.toLowerCase()]}返回null == b?null:b} overrideMimeType:函数(a) {return t ||(k.mimeType = a),this} pipe:function(){var a = arguments; return n.Deferred(function(c){n.each(b,function(b,f){var g = n.isFunction(a [b])&& a [b]; e [f [1]](function(){var a = g && g.apply(this,arguments); a && n.isFunction(a.promise)?a .promise()。done(c.resolve).fail(c.reject).progress(c.notify):cf [0] +“ With”})}),a = null})。promise()} progress :function(){if(h){var c = h.length;!function g(b){n.each(b,function(b,c){var d = n.type(c);“ function” === d?a.unique && k.has(c)|| h.push(c):c && c.length &&“ string”!== d && g(c)})}(参数),d?f = h.length: b &&(e = c,j(b))}返回此}承诺:函数(a){返回 null!= a?n.extend(a,d):d} readyState:4setRequestHeader:function(a,b){var c = a.toLowerCase(); return t ||(a = s [c] = s [ c] || a,r [a] = b),此}状态:函数(){返回c}状态:200状态代码:函数(a){var b; if(a)if(2> t)for(b在a)q [b] = [q [b],a [b]]中;否则v.always(a [v.status]);返回此}状态文本:“ load”成功:function(){if(h ){var c = h.length;!function g(b){n.each(b,function(b,c){var d = n.type(c);“ function” === d?a.unique && k .has(c)|| h.push(c):c && c.length &&“ string”!== d && g(c)})}(参数),d?f = h.length:b &&(e = c,j( b))}返回此}然后:function(){var a = arguments; return n.Deferred(function(c){n.each(b,function(b,f){{var g = n.isFunction(a [ b])&& a [b]; e [f [1]](function(){var a = g && g.apply(this,arguments); a && n.isFunction(a.promise)?a.promise()。done(c .resolve).fail(c.reject).progress(c.notify):cf [0] +“ With”})}),a = null})。promise()} proto :对象

有什么想法我做错了吗?

尝试这个。 希望问题可能与contentType: "application/json", dataType: 'jsonp'

    var url = 'http://localhost:3000/categories/?callback=?';

    $.ajax({
        type: 'GET',
        url: url,
        success: function(data) {
           console.log(data);
        },
        error: function(e) {
           console.log(e);
        }
    });

您可以尝试更改此行吗?

cache: false, // we do not need any browser posibble caches here..
success: callback, 
// remove this line: jsonpCallback: 'jsonCallback', 

并在URL中放弃?回调

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM