- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个非常困难的问题。我有一个页面,用户填写一些数据并单击按钮,将所有参数保存到 json 对象中。在本地保存数据后,用户单击另一个按钮,该按钮调用 ajax 方法,该方法在内部调用同一网站中添加的 Web 服务方法,以将数据存储在服务器上。
我的问题是这样的,当用户将数据保存在本地并离开系统并在一段时间后返回时,它单击第二个按钮将数据存储在服务器上。 ajax方法抛出错误(有时是401,有时是net::ERR_CONNECTION_RESET)。但是当他再次单击该按钮时,一切都会成功运行。
我已经问过我的前辈,他现在希望在这种情况下注销。但我很困惑如何在客户端验证服务器端 session 以便注销用户。
点击第二个按钮调用的ajax方法
// symbol "$" is used to make attribute property in XML. for this symbol "$" is replaced by symbol "@" in aspx.cs file.
//this method is used to call Ajax Helper Class method.
function MethodWithComplexParameterClient(jsEmp) {
try {
var jsonText = JSON.stringify(jsEmp); //Convert javascript value to a JSON String
var rowactioncount = "0";
if ($("#ContentPlaceHolder1_RuleGeneratorRBL input")[1].checked) {
rowactioncount = $("#ContentPlaceHolder1_RowActionCountHdn").val();
}
$.ajax(
{
type: "POST",
url: "AjaxHelperWebService.asmx/MethodWithComplexParameter",
data: '{"jsonParam": ' + jsonText + ',"rowactioncount":"' + rowactioncount + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
if (Number(msg.d) == 1) {
if ($("#ContentPlaceHolder1_RuleGeneratorRBL input")[1].checked) {
alert("Rule Uploaded Successfuly. Rule Name: " + '"' + $("#ContentPlaceHolder1_RuleNameTB").val().trim() + '.xml"');
var IsEMIProgramtype = false;
for (var i = 0; i < $("#RuleFileUL").children().length; i++) {
if (($("#RuleFileUL").children()[i].id).contains('EMI')) {
IsEMIProgramtype = true;
break;
}
}
if (IsEMIProgramtype)
alert("Scheme has been edited. Please update HDFC internal TID, RBL internal TID, SBI SKU Code if mapped with old scheme");
}
else {
var lRuleName = $("#ContentPlaceHolder1_RuleNameTB").val().trim();
var ruleNameLength = lRuleName.length;
var next_index = 50;
var madeOutRuleName = "";
for (ii = 0; ii < ruleNameLength; ii = ii + 50) {
var lSplitedRuleName = lRuleName.substring(ii, next_index);
madeOutRuleName = madeOutRuleName + lSplitedRuleName + "\n";
next_index = next_index + 50;
}
if (next_index == 50) {
alert("Rule Created Successfuly. Rule Name: " + '"' + lRuleName + '.xml"');
}
else {
alert("Rule Created Successfuly. Rule Name: " + '"' + madeOutRuleName + '.xml"');
}
}
$("#RuleFileUL").empty();
$("#ContentPlaceHolder1_RuleFileLblTB").val("Rule");
document.getElementById('ContentPlaceHolder1_RuleFileLblTB').style.height = "15px";
document.getElementById('ContentPlaceHolder1_ParamHeaderLbl').style.display = 'none';
document.getElementById('ContentPlaceHolder1_DefaultParamTable').style.display = 'none';
document.getElementById("ContentPlaceHolder1_RulePropertyTable").style.display = "none";
document.getElementById("ContentPlaceHolder1_ValocityCheckTbl").style.display = "none";
$("#ContentPlaceHolder1_ExistingSchemaSuggestTB").val("");
document.getElementById("ContentPlaceHolder1_ExistingSchemaTbl").style.display = "none";
document.getElementById("ContentPlaceHolder1_SchemaPropertiesSaveBtnTbl").style.display = "none";
$("#ContentPlaceHolder1_RuleNameTB").val("");
$("#RuleStartHrDTPickerTB").val("");
$("#RuleEndHrDTPickerTB").val("");
Object.keys(ProgramTypeObjHT).forEach(function (key) {
delete ProgramTypeObjHT[key];
});
Object.keys(SchemaObjHT).forEach(function (key) {
delete SchemaObjHT[key];
});
Object.keys(EMIObjHT).forEach(function (key) {
delete EMIObjHT[key];
});
Object.keys(DefaultPTParams).forEach(function (key) {
delete DefaultPTParams[key];
});
Object.keys(SchemaParams).forEach(function (key) {
delete SchemaParams[key];
});
Object.keys(EMIParamsHT).forEach(function (key) {
delete EMIParamsHT[key];
});
}
else if (msg.d == "2") {
alert("Rule Generation Failed.");
}
else if (msg.d == "4") {
$("#ContentPlaceHolder1_RuleNameTB").val("");
alert("Rule Name Already Exists, Please Enter Different Rule Name.");
$("#ContentPlaceHolder1_RuleNameTB").focus();
}
else if (msg.d == "5") {
alert("Duplicate Schema Name Found. Please Check Schema Names.");
}
else if (msg.d == "6") {
alert("Rule Is Updated By Someone Else. Please Refresh.");
}
else {
alert("Exception Occurred.");
}
},
error: function ( x, e) {
debugger;
if (x.status == 401) {
alert("The call to the server side failed. due to unauthorised access. " + x.status);
CreateXMLBtnClientClick();
}
else {
alert("The call to the server side failed. " + x.responseText);
console.log(x, e);
console.log(x.responseText);
console.log(x.status);
console.log(e);
[![enter image description here][1]][1] }
}
}
);
return false;
}
catch (err) {
alert(err);
}
}
最佳答案
ajax方法抛出错误
好吧,捕获此错误,如果发生则重定向到注销页面。非常简单,当您捕获 AJAX 错误时,您可以执行以下操作:
window.location.href = 'logout.html'
或其他。参见这里:Window.location.href and Window.open () methods in JavaScript
您没有发布足够的信息来获取更具体的帮助。
关于javascript - 在从单击按钮时调用的 ajx 方法调用 Web 服务方法之前验证 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35131828/
我有以下使用 ajax 加载页面的简单页面。 function loadPage(href) { var xmlhttp = new XMLHttpReques
我有一个非常困难的问题。我有一个页面,用户填写一些数据并单击按钮,将所有参数保存到 json 对象中。在本地保存数据后,用户单击另一个按钮,该按钮调用 ajax 方法,该方法在内部调用同一网站中添加的
我有一个功能来检查电子邮件是否存在,但我只想在电子邮件不存在时提交表单 所以我写了以下函数: $("#form-1").on("submit",function(e){ e.preventD
如果我使用安装的 Nuget 包 Microsoft.AspNet.FriendlyUrls v 1.0.2 和 Microsoft.AspNet.Identity v.1.0.0. 从 jQuery
我是一名优秀的程序员,十分优秀!