Javascript Ajax请求不会从服务器返回答案

Javascript Ajax请求不会从服务器返回答案,javascript,html,asp.net-mvc,Javascript,Html,Asp.net Mvc,我在JS中有这样一个代码: $.ajax({ url: $("body").data("url") + "/Documents/CheckDoc", data: { docID: id }, dataType: 'text', }).success(function (json) { if (json.status) { if (json.result) { //

我在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 无论如何都要执行 这就好像是从这个功能中飞出来,不再返回到它

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


谢谢

您的代码中似乎有一些错误,您在
数据类型:'text',
by
})之后关闭了代码
,请尝试此操作并告知我们:

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