Go homepage(回首页) Upload pictures (上传图片) Write articles (发文字帖)
The author:(作者)归海一刀published in(发表于) 2014/3/16 2:55:44 解决Ajax中文乱码问题_[AJAX教程]
网上有很多解决这个问题的方法,试了一下都不好用,自己就对于这些方法测试了一下,然后逐个排除无用的设置,最后得到了最简单的方案。
js代码: 得到XmlHttpRequest的类Code 1function HttpRequest() 2{ 3 //取得Request对象 4 this.Request=function(){ 5 try 6 { 7 if(window.XMLHttpRequest) request=new XMLHttpRequest(); 8 if(!request)request=new ActiveXObject("Microsoft.XMLHTTP"); 9 if(!request)request=new ActiveXObject("Msxml2.XMLHTTP");10 return request;11 }12 catch(e)13 {14 alert("不支持XMLHTTPRequest");15 }}16}调用过程:Code 1<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AjaxTest._Default" %> 2 3 4 5 6 Untitled Page 7 8 910 34353637 38 39 40 41 424344后台取得输入值: protected void Page_Load(object sender, EventArgs e) { string value = Request["Value"]; }测试过,可以得到正确的输入字符。来源:http://www.cnblogs.com/jingtao
赞