ajax数据传输方式实例详解(4)

using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebTest2008 { public partial class AjaxOperations : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request["action"]) && Request["action"] == "jsonOp") // 处理JSON { string responseJsonTxt = ""; string tempStr = Request["sendStr"].Trim(new char[] { '{', '}' }); // 在服务器上解释JSON需要引用一个能够转化JSON的组件:Json.Net,这里简单测试,略过Json.Net if (tempStr.Split(new char[] { ',' })[0].Split(new char[] { ':' })[1] == "\"test\"" && tempStr.Split(new char[] { ',' })[1].Split(new char[] { ':' })[1] == "\"test\"") { responseJsonTxt = "{\"msg\":\"验证通过!\"}"; // 测试用 } else responseJsonTxt = "{\"msg\":\"验证失败!\"}"; Response.Write(responseJsonTxt); Response.End(); } }

jsTest.html引入json.js文件(必须下载json.js文件,否则js报错),如下:

<html> <head> <title>js test</title> <script src="https://www.jb51.net/js/json.js" type="text/javascript"></script> <script src="https://www.jb51.net/js/testJs.js" type="text/javascript"></script> </head> <body> <form> <div> 用户名:<input type="text" /> &nbsp;密码:<input type="password" onblur="validatePwd(this)" /></div> </form> </body> </html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wfygsj.html