C# ajax调用在第二次请求相同url时失败
我正在将Ajax转换为C#方法,它在第一次请求时工作良好,但在第二次请求时失败。我在ajax请求中设置了cache:false。我还添加了标题C# ajax调用在第二次请求相同url时失败,c#,jquery,ajax,C#,Jquery,Ajax,我正在将Ajax转换为C#方法,它在第一次请求时工作良好,但在第二次请求时失败。我在ajax请求中设置了cache:false。我还添加了标题 $.ajaxSetup({ headers: { "Cache-Control": "no-cache" } }); $.ajax({ type: 'POST', url: 'Default.aspx/ProcessPayment', dataType: 'json', data: JSON.stringify(
$.ajaxSetup({
headers: { "Cache-Control": "no-cache" }
});
$.ajax({
type: 'POST',
url: 'Default.aspx/ProcessPayment',
dataType: 'json',
data: JSON.stringify({ PaymentProcessData: PaymentProcessData }),
contentType: "application/json; charset=utf-8",
cache: false,
//beforeSend: function () {
// $('#loadingDiv').show();
//},
success: function (data) {
GetproductsForBinding(1);
},
error: function (msg) {
}
});
但什么都不管用。有人能帮忙吗。这是我的Ajax代码
function GetproductsForBinding(ddlID) {
$.ajax({
type: 'GET',
url: 'Default.aspx/BindProductsToDropdownlist?dummy="'+Date.now()+'"',
dataType: 'json',
contentType: "application/json; charset=utf-8",
async: false,
cache:false,
success: function (data) {
debugger;
var data = JSON.parse(data.d);
$.each(data, function (key, val) {
})
},
error: function (msg, err, er) {
debugger;
}
});
}
$.ajax({
type: 'POST',
url: 'Default.aspx/ProcessPayment',
dataType: 'json',
data: JSON.stringify({ PaymentProcessData: PaymentProcessData }),
contentType: "application/json; charset=utf-8",
cache: false,
//beforeSend: function () {
// $('#loadingDiv').show();
//},
success: function (data) {
GetproductsForBinding(1);
},
error: function (msg) {
}
});
第二个请求失败并转到错误块,错误表示发生了网络错误。非常感谢您的帮助。我要休息两天
$.ajax({
type: 'POST',
url: 'Default.aspx/ProcessPayment',
dataType: 'json',
data: JSON.stringify({ PaymentProcessData: PaymentProcessData }),
contentType: "application/json; charset=utf-8",
cache: false,
//beforeSend: function () {
// $('#loadingDiv').show();
//},
success: function (data) {
GetproductsForBinding(1);
},
error: function (msg) {
}
});
我要把第二个变成这样
$.ajax({
type: 'POST',
url: 'Default.aspx/ProcessPayment',
dataType: 'json',
data: JSON.stringify({ PaymentProcessData: PaymentProcessData }),
contentType: "application/json; charset=utf-8",
cache: false,
//beforeSend: function () {
// $('#loadingDiv').show();
//},
success: function (data) {
GetproductsForBinding(1);
},
error: function (msg) {
}
});
找到答案我自己把第二个电话延迟2秒效果很好
$.ajax({
type: 'POST',
url: 'Default.aspx/ProcessPayment',
dataType: 'json',
data: JSON.stringify({ PaymentProcessData: PaymentProcessData }),
contentType: "application/json; charset=utf-8",
cache: false,
//beforeSend: function () {
// $('#loadingDiv').show();
//},
success: function (data) {
GetproductsForBinding(1);
},
error: function (msg) {
}
});
:)您不需要var data=JSON.parse(data.d);,由于它已经是一个json objecton成功添加代码=>alert(“成功”);第二次、第三次检查警报。第二次请求的代码在哪里?您收到的错误/状态代码是什么?您可以发布错误响应吗?首先,我在页面加载时调用该方法,然后从另一个ajax函数成功块发出第二个请求。我得到的错误代码是13,即Dom异常“发生网络错误”。谢谢你的回答。这并不是问题的答案。要评论或要求作者澄清,请在他们的帖子下方留下评论——你可以随时对自己的帖子发表评论,一旦你有足够的评论,你就可以发表评论了。
$.ajax({
type: 'POST',
url: 'Default.aspx/ProcessPayment',
dataType: 'json',
data: JSON.stringify({ PaymentProcessData: PaymentProcessData }),
contentType: "application/json; charset=utf-8",
cache: false,
//beforeSend: function () {
// $('#loadingDiv').show();
//},
success: function (data) {
GetproductsForBinding(1);
},
error: function (msg) {
}
});