我在 VS2012 中使用 ASP.NET MVC 4。
我正在使用包来缩小我的 JavaScript 代码。
我的捆绑代码是:
bundles.Add(new ScriptBundle("~/bundles/inline").Include("~/Scripts/inline/_layout_inline.js"));
JavaScript 源代码如下所示:
function requestPurchaseCompanies()
{
var urlStr = '/Search/PurchaseSelectedCompanys';
$.ajax({
url: urlStr,
dataType: 'json',
type: 'POST',
error: function (result, status, error) {
var message = JSON.parse(result.responseText);
parsePurchaseError(message);
},
success: function (data) {
// get the result and do some magic with it
var message = data.Message;
if (window.location.href.indexOf('page=') < 0) {
var url = '/Search/PagingDisplay';
var params = '?page=1';
window.location = 'http://' + window.location.host + url + params;
} else {
window.location = window.location;
}
}
});
}
注意这一行:error: function (result, status, error) {
这是呈现的缩小 JavaScript:
function requestPurchaseCompany(n, t, i, r) {
var u = undefined,
f, e, o, s, h;
n != null && i == "SearchResults" ? (f = $(n).closest("div.result")[0], f && f != "undefined" && (e = $(f).children("span[id=SelectDuns]")[0], e && e != "undefined" && (o = $(e).children("input:hidden")[0], o && o != "undefined" && (u = new CompanySelectState, u.CompanyID = o.value)))) : t != undefined && (u = new CompanySelectState, u.CompanyID = t), u && u != undefined && (s = "/Search/PurchaseCompany", h = JSON.stringify(u), $.ajax({
url: s,
type: "POST",
dataType: "json",
data: h,
contentType: "application/json; charset=utf-8",
error: function (n) {
var r = JSON.parse(n.responseText);
parsePurchaseError(r)
},
success: function (t) {
var e = t.Message,
u, f;
t.State == !0 && $(n).attr("disabled", ""), n != null && i == "SearchResults" ? window.location.href.indexOf("page=") < 0 ? (u = "/Search/PagingDisplay", f = "?page=1", window.location = "http://" + window.location.host + u + f) : window.location = window.location : window.location = window.location, r != undefined && r == !0 && window.opener != undefined && window.opener.location != undefined && window.opener.location.reload()
}
}))
}
注意第 10 行:error:function(n){
所以它开始为:
error: function (result, status, error) {
并呈现为:
error:function(n){
问题在于具有一个参数的缩小代码将该参数视为错误参数,而不是我需要的 XMLHttpRequest。
我该如何解决?