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')
    }
});