ajax GET方式提交,中文参数乱码的问题
在构造url是用javascript自带的encodeURIComponent方法将参数进行编码,下面是我的代码
var url = "handel.jsp?name="+encodeURIComponent(document.form1.name.value);
httpRequest = createHttpRequest();
httpRequest.onreadystatechange = aa;
httpRequest.open("GET",url,true);
httpRequest.send(null);
后台直接接受就可以得到中文,不需要转码
String nameFalse = this.getRequest().getParameter("name")。
相关文档:
<script type="text/javascript">
function addUrl(){
//1、设置请求url地址
var name = document.getElementById("name").value;
var text = document.getElementById("url").value;
var url = "insertUrl.do?name="+name+
"&url="+text+"&time"+new Date() ;
//2、创建xmlHttpRequest对象
x ......
1、创建
XMLHttpRequest
对象的一个实例
var xmlHttp;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if ( ......
function CreateXmlHttp()
{
if(window.ActiveXObject)
{
try
{
XmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){};
try
{
XmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){};
}
else if(window.XMLHt ......