Java脚本
$('#senurl').click(function () {
$.ajax({
type: "POST",
url: "/Admin/Coupon1/Reject",
dataType: "json",
data: "id="+@Model.id+"&url="+@url
});
});
ReferenceError:未定义过期 [打破此错误]
数据:“id =”+ 2925 +“& url =”+已过期
答案 0 :(得分:2)
你可能想要(但也见下文):
$('#senurl').click(function () {
$.ajax({
type: "POST",
url: "/Admin/Coupon1/Reject",
dataType: "json",
data: "id=@Model.id&url=@url"
});
});
...因为您必须考虑浏览器看到的内容,以及服务器是否@url
被Expired
替换,您可以从错误中看出浏览器看到的代码是:
data: "id="+2925+"&url="+Expired // <=== What the browser sees with your current code
更好的是,让jQuery通过传递一个对象来处理所需的任何潜在的URI编码:
$('#senurl').click(function () {
$.ajax({
type: "POST",
url: "/Admin/Coupon1/Reject",
dataType: "json",
data: {id: @Model.id, url: "@url"}
});
});
如果您不想传递jQuery对象并让它为您处理URI编码,那么您将需要自己处理它:
data: "id=@Model.id&url=" + encodeURIComponent("@url")
答案 1 :(得分:0)
$('#senurl')。click(function(){
$.ajax({
type: "POST",
url: "/Admin/Coupon1/Reject",
dataType: "json",
data: "{id:'" + @Model.id + "', 'url': " + @url + "}",
success: function (response) {
alert( response.d);
},
error: function (data) {
alert(data);
},
failure: function (msg) {
}
});
});
试试这个它工作正常。如果您使用的是url路由,那么您可能会遇到其他错误。 所以最好得到respone输出并检查..
答案 2 :(得分:-1)
我认为这是因为@url变量被分配了数据Expired
而没有引号。