我在 C# 中有一个方法,它创建用户凭据的 JSON 对象。下面是 CS 文件。
public string CreateLoginjson(string strErrorType, bool blIsAuthenticated)
{
StringBuilder sbLoginJson = new StringBuilder();
if (blIsAuthenticated)
{
sbLoginJson.Append("{LoginSuccess:1");
}
else
{
sbLoginJson.Append("{LoginSuccess:0");
}
if (strErrorType != string.Empty)
{
if (strErrorType.TrimEnd(new char[] { ',' }) == "Token" ||
strErrorType.TrimEnd(new char[] { ',' }) == "BlankToken")
{
sbLoginJson.Append(",txtTestTokenNumber1:\"Error\"");
sbLoginJson.Append(",txtTestTokenNumber2:\"Error\"");
sbLoginJson.Append(",txtTestTokenNumber3:\"Error\"");
sbLoginJson.Append(",txtTestTokenNumber4:\"Error\"");
}
if (strErrorType.TrimEnd(new char[] { ',' }) == "Password")
{
sbLoginJson.Append(",txtPassword:\"Error\"");
}
if (strErrorType.TrimEnd(new char[] { ',' }) == "UserName")
{
sbLoginJson.Append(",UserName:\"Error\"");
}
string strLoadErrorControlMessage = LoadErrorControl(strErrorType,
string.Empty);
if (strLoadErrorControlMessage!= string.Empty)
{
sbLoginJson.Append(",ErrorMessage:
'" + strLoadErrorControlMessage + "'");
}
}
sbLoginJson.Append("}");
var LoginJson = sbLoginJson.ToString();
return LoginJson;
}
现在,我需要将 LoginJson 传递给一个 JS 函数,该函数检查是否提供了不正确的凭据,该函数找到控件并为其添加一个属性 JS
function GetLoginJson(strLoginJson) {
if (strLoginJson != '' && strLoginJson != undefined) {
var objLoginJson = strLoginJson;
if (objLoginJson.LoginSuccess == "1") {
}
else if (objLoginJson.LoginSuccess == "0") {
if (objLoginJson.txtUserName != ''
&& objLoginJson.txtUserName != undefined)
{
$('#txtUserName').attr("class", objLoginJson.txtUserName);
}
else
{
$('#txtUserName').attr("class", "Input");
}
if (objLoginJson.txtPassword != ''
&& objLoginJson.txtPassword != undefined)
{
$('#txtPassword').attr("class", objLoginJson.txtPassword);
}
else
{
$('#txtPassword').attr("class", "Input");
}
if (objLoginJson.txtTestTokenNumber1 != ''
&& objLoginJson.txtTestTokenNumber1 != undefined)
{
$('#txtTestTokenNumber1').attr("class",
objLoginJson.txtTestTokenNumber1);
}
else
{
$('#txtTestTokenNumber1').attr("class", "Error");
}
if (objLoginJson.txtTestTokenNumber2 != ''
&& objLoginJson.txtTestTokenNumber2 != undefined)
{
$('#txtTestTokenNumber2').attr("class",
objLoginJson.txtTestTokenNumber2);
}
else
{
$('#txtTestTokenNumber2').attr("class", "Error");
}
if (objLoginJson.txtTestTokenNumber3 != '' &&
objLoginJson.txtTestTokenNumber3 != undefined) {
$('#txtTestTokenNumber3').attr("class",
objLoginJson.txtTestTokenNumber3);
}
else
{
$('#txtTestTokenNumber3').attr("class", "Error");
}
if (objLoginJson.txtTestTokenNumber4 != '' &&
objLoginJson.txtTestTokenNumber4 != undefined) {
$('#txtTestTokenNumber4').attr("class",
objLoginJson.txtTestTokenNumber4);
}
else
{
$('#txtTestTokenNumber4').attr("class", "Error");
}
$('#ErrorControl').html('');
}
}
}
我想将 JSON 变量从 CS 传递给这个 jQuery 语句 `$('#ErrorControl').html('');'
谢谢