微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Ajax 请求没有从服务器返回答案

如何解决Ajax 请求没有从服务器返回答案

我在 JS 中有这样的代码

$.ajax({
    url: $("body").data("url") + "/Documents/CheckDoc",data: {
        docID: id
    },dataType: 'text',}).success(function (json) {
    if (json.status) {
        if (json.result) { // word template format
            window.open($("body").data("url") + '/Case/OpenEnforcementDocument?DocID=' + id + '&RRcode=' + RR);

        }
        else { //html template format
            window.open($("body").data("url") + '/EnforcementPrintout/Printout?DocID=' + id + '&copys=' + copys,"_blank");
        }
    }
    else {
        toastr.error(json.message);
    }

});
toastr.error("error");

指的是服务器端的CheckDoc函数 在那里它工作得很好但是当它回到 JavaScript 时 它不会返回 .success 并且不会到达函数的最后一行:toastr.error 无论如何都必须进行 就好像从这个函数飞出去了,再也回不去了

有人可能知道问题出在哪里 对我有很大帮助

谢谢

解决方法

您的代码似乎存在错误,您在 dataType: 'text', 之后的 }) 关闭了代码,请尝试此操作并告诉我们:

$.ajax({
    type: "POST",url: $("body").data("url") + "/Documents/CheckDoc",data: { docID: id },contentType: "application/json; charset=utf-8",dataType: 'text',success: function (json) {
        if (json.status) {
            if (json.result) { // word template format
                window.open($("body").data("url") + '/Case/OpenEnforcementDocument?DocID=' + id + '&RRcode=' + RR);

            }
            else { //html template format
                window.open($("body").data("url") + '/EnforcementPrintout/Printout?DocID=' + id + '&copys=' + copys,"_blank");
            }
        }
        else {
            toastr.error(json.message);
        }

    },failure: function (response) {
        alert("failure");
    },error: function (xhr,ex) {
        alert('error')
    }
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。