asp.net+js实现批量编码与解码的方法
程序员文章站
2023-12-20 15:37:58
本文实例讲述了asp.net+js实现批量编码与解码的方法。分享给大家供大家参考,具体如下:
<%@ page language="c#" autoeven...
本文实例讲述了asp.net+js实现批量编码与解码的方法。分享给大家供大家参考,具体如下:
<%@ 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 runat="server"> <title></title> <mce:script src="jquery-1.3.2.min.js" mce_src="jquery-1.3.2.min.js" type="text/javascript"></mce:script> <mce:script type="text/javascript"><!-- var data = {}; data.id = 1; data.name = "1 & 2"; data.desc = "<b> def </b>"; var clientmsg = ""; clientmsg+="<font color='green'>1: 客户端编码之前:<br/>"; for (var name in data) { clientmsg+=(name + ":" + data[name] + "<br/>"); } clientmsg += "1: 客户端编码之后:<br/>"; escapedata(data); for (var name in data) { clientmsg+=name + ":" + data[name] + "<br/>"; } clientmsg += "</font>"; $.post("default.aspx", data, function (data) { document.write(clientmsg+"<br/>"+data); }); function escapedata(data) { for (var name in data) { data[name] = escape(data[name]); } } // --></mce:script> </head> <body> <form id="form1" runat="server"> <div id="divclient" style="color:green;" mce_style="color:green;" > </div> </form> </body> </html>
c#代码如下:
using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; public partial class _default : system.web.ui.page { protected void page_load(object sender, eventargs e) { if (request["id"]!=null) { string msg = ""; msg += "<font color='red'>服务器得到的值(解码前):<br/>"; foreach (string s in request.form.allkeys) { msg += string.format("{0}:{1}<br/>", s, request.form[s]); } msg += "服务器得到的值(解码后):<br/>"; foreach (string s in request.form.allkeys) { msg += string.format("{0}:{1}<br/>", s, httputility.urldecode(request.form[s])); } msg += "</font>"; msg += string.format("未编码的字符解码1ab&<b>小</b>:{0}",httputility.urldecode("1ab&<b>小</b>")); ; response.write(msg); response.end(); } } }
希望本文所述对大家asp.net程序设计有所帮助。