<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1
-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Login Page</title>
<script src="Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="wholeContent">
<div id="login">
<table border="2">
<tr>
<td>
User Id
</td>
<td>
<input type="text" id="txtId" name="txtId" />
</td>
</tr>
<tr>
<td>
Password
</td>
<td>
<input type="text" id="txtPwd" name="idPwd" />
</td>
</tr>
<tr>
<td>
<input type="button" id="btnSubmit" value="Login" />
</td>
</tr>
</table>
</div>
<div id="success">
</div>
<div id="error">
</div>
</div>
<script type="text/javascript">
$(document).ready(function()
{
$("#btnSubmit").click(function()
{
var uid = $("#txtId").val();
var pwd = $("#txtPwd").val();
var data=JSON.stringify({uid:uid,pwd:pwd});
$.ajax({
type: "POST",
url: "Default.aspx/ValidationWebMethod",
data: "{ 'uid': '" + uid + "','pwd': '"+pwd+"'}",
// data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: "false",
success: function (data)
{
alert(" Successful Login "+data.d);
// location.reload();
},
error: function(resp,textStatus,errorThrown)
{
alert("error : " + errorThrown + " || Check your Id and Password || "+ resp.d);
}
});
});
});
</script>
</form>
</body>
</html>
这是我的代码隐藏(部分代码)
[System.Web.Services.WebMethod]
public static void ValidationWebMethod(string uid, string pwd)
{
string text = uid + " : " + pwd;
System.IO.File.WriteAllText(@"D:\TrackLog.txt", text);
string[] flags = new string[1];
// bool valid = true;
if (uid.Equals("arijit") && pwd.Equals("admin"))
{
flags[0] = "true";
// return flags;
}
else
{
flags[0]="false";
// return flags;
}
}
现在,当我单击按钮 (btnSubmit) 时,它给出的语法错误:无效字符(警告框中的 errorThrown 变量)..请你告诉我为什么会这样?