gpt4 book ai didi

javascript - 在从单击按钮时调用的 ajx 方法调用 Web 服务方法之前验证 session

转载 作者:行者123 更新时间:2023-12-03 07:47:54 26 4
gpt4 key购买 nike

我有一个非常困难的问题。我有一个页面,用户填写一些数据并单击按钮,将所有参数保存到 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com