【发布时间】:2013-12-02 06:32:12
【问题描述】:
请考虑以下代码。我正在使用下面的 ajax 调用加载我的产品视图。
$.ajax({
cache: true,
type: "GET",
url: url,
data: json.stringify(data),
success: function (data) {
var mainview = $(data).find(".maindiv");
$('.maindiv').replaceWith(mainview);
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert('Error Occured...... No Products Found');
},
complete: function () { subscribeProgress.hide(); }
});
现在,当我加载此视图时,每个产品都有一个添加到购物车按钮,在该按钮上执行另一个 ajax 调用以检查客户是否已注册或访客,并显示相应的注册弹出窗口。现在注册客户,调用了另一个ajax方法,正常工作,但是json数据没有返回成功,直接显示在页面上。
下面是弹窗注册客户的id码
$('#formpopupReg').unbind('submit');
$('#formpopupReg').bind('submit', function () {
if ($(this).valid()) {
$.ajax({
url: this.action,
type: this.method,
// you can post your model with this line
data: $(this).serialize(),
success: function (data) {//Json should get back to this call but doesnt
if (data.status == "Wrong email") {
$('#modelerrors').text("Wrong email");
}
if (data.status == "emailexists") {
//Code on Error
}
if (data.status == "registersuccess") {
location.reload();
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert('Internal Error.');
},
complete: function () { }
});
}
return false;
});
任何解决方案。我希望 json 数据返回成功调用。
【问题讨论】:
-
尝试在
success: function (data)中查看"data"是否为带有console.log(data)的数组或对象。 -
实际上当我用ajax加载页面时,通过inspect元素看不到任何jquery代码
标签: c# ajax asp.net-mvc-3 jquery