dongmo8943 2011-12-14 08:47
浏览 56

jQuery ajax仅在第二次尝试时提交

I have a really strange problem with jquery. I'm trying to send something to the server and get data back. I have success function and error function. when the jquery ajax is invoked the first time - the error function gets called. the second time (on the same page) - it's successful. I have not idea why is that. here is my javascript code:

$.ajax ({
    type : 'POST',
    url: "/checkout/test",
    context: document.body,
    success: function(data){
        alert (data);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
        alert(textStatus)
    }
});

on the server side, it's just a php page returning "testing" string without any html.

this is the content of XMLHttpRequest when the error occures:

readyState: 0;
setRequestHeader: function (a, b) {
    if (!s) {
        var c = a.toLowerCase();
        a = m[c] = m[c] || a, l[a] = b;
    }
    return this;
};
getAllResponseHeaders: function () {
    return s === 2 ? n : null;
};
getResponseHeader: function (a) {
    var c;
    if (s === 2) {
        if (!o) {
            o = {};

            while ((c = bD.exec(n))) {
                o[c[1].toLowerCase()] = c[2];
            }
        }
        c = o[a.toLowerCase()];
    }

    return c === b ? null : c;
};
overrideMimeType: function (a) {
    s || (d.mimeType = a);
    return this;
};
abort: function (a) {
    a = a || "abort", p && p.abort(a), w(0, a);
    return this;
};
pipe: function (a, c) {
    return f.Deferred(function (d) {
        f.each({
            done: [a, "resolve"],
            fail: [c, "reject"]},
            function (a, c) {
                var e = c[0], g = c[1], h;
                f.isFunction(e) ? b[a](function () {
                    h = e.apply(this, arguments), h && f.isFunction(h.promise) ? h.promise().then(d.resolve, d.reject) : d[g + "With"](this === b ? d : this, [h]);
                }) : b[a](d[g]);
            });
        }).promise();
    };
    always: function () {
        return b.done.apply(b, arguments).fail.apply(this, arguments);
    };
    then: function (a, c) {
        b.done(a).fail(c);
        return this;
    };
    promise: function (a) {
        if (a == null) {
            if (d) {
                return d;
            }

            d = a = {};
        }
        var c = g.length;
        while (c--) {
            a[g[c]] = b[g[c]];
        } return a;
    };
    isRejected: function () {
        return !!c || !!b;
    };
    isResolved: function () {
        return !!c || !!b;
    };
    fail: function () {
        if (!d) {
            var c = arguments, g, h, i, j, k;
            b && (k = b, b = 0);
            for (g = 0, h = c.length; g < h; g++) {
                i = c[g], j = f.type(i), j === "array" ? e.done.apply(e, i) : j === "function" && a.push(i);
            }
            k && e.resolveWith(k[0], k[1]);
        }
        return this;
    };
    done: function () {
        if (!d) {
            var c = arguments, g, h, i, j, k;
            b && (k = b, b = 0);
            for (g = 0, h = c.length; g < h; g++) {
                i = c[g], j = f.type(i), j === "array" ? e.done.apply(e, i) : j === "function" && a.push(i);
            } k && e.resolveWith(k[0], k[1]);
        }
        return this;
    };
    success: function () {
        if (!d) {
            var c = arguments, g, h, i, j, k;
            b && (k = b, b = 0);
            for (g = 0, h = c.length; g < h; g++) {
                i = c[g], j = f.type(i), j === "array" ? e.done.apply(e, i) : j === "function" && a.push(i);
            }
            k && e.resolveWith(k[0], k[1]);
        }
        return this;
    };
    error: function () {
        if (!d) {
            var c = arguments, g, h, i, j, k;
            b && (k = b, b = 0);
            for (g = 0, h = c.length; g < h; g++) {
                i = c[g], j = f.type(i), j === "array" ? e.done.apply(e, i) : j === "function" && a.push(i);
            }
            k && e.resolveWith(k[0], k[1]);
        }
        return this;
    };
    complete: function () {
        if (!d) {
            var c = arguments, g, h, i, j, k;
            b && (k = b, b = 0);
            for (g = 0, h = c.length; g < h; g++) {
                i = c[g], j = f.type(i), j === "array" ? e.done.apply(e, i) : j === "function" && a.push(i);
            }
            k && e.resolveWith(k[0], k[1]);
        }
        return this;
    };
    statusCode: function (a) {
        if (a) {
            var b;
            if (s < 2) {
                for (b in a) {
                    j[b] = [j[b], a[b]];
                }
            } else {
                b = a[v.status], v.then(b, b);
            }
        }
        return this;
    };
    responseText: ;
    status: 0;
    statusText: error; 

Thank you for your help

  • 写回答

3条回答 默认 最新

  • dongqi8114 2011-12-14 08:55
    关注

    I guess you need to provide file extension to the url.

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程