2。 提交的时候已经 用encodeURIComponent(item.value) 解析了提交编码, 并且 xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=gb2312");
3 。 如果用jsp的action 提交则没有问题 因为使用了<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
23 个解决方案
#1
我可以看看你ajax post的URL代码么?
#2
jsp页上面就要设置 本页输出编码是gb2312
#3
var content = " <html xmlns='http://www.w3.org/1999/xhtml'>";
content += "<head><meta http-equiv='Content-TYPE' content=text/html; charset=gb2312>";
content += "<body >";
content += "<input type='text' name='posturl' value='' style='width:300px; border:1px solid #006699'>形式如:";
content += "<form name='form1' id='popFormSubmit' action='a.jsp' target='_blank' method='post' style='border:0px; padding:0px; margin:0px;'>";
content += "<input type='hidden' name='ct' value='1'/>";
content += "<input type='hidden' name='cm' value='1'/>";
content += "<div id='m_blognew' class='modbox''>";
content += "<table border='0' cellspacing='6' cellpadding='3' class='formhd' width='90%' bgcolor='#ffffff' align='center'>";
content += "<tr><td width='60' class='f14' nowrap>标题:</td>";
content += "<td><input type='text' name='spBlogTitle' id='spBlogTitle' style='width:540px' value='uuuuuuuuuuu' onChange=''></td>";
content += "<tr><td width='60' class='f14' nowrap>内容: <td><div id='spBlogText'></div><input type='hidden' name='spBlogText' /></td></tr>";
content += "<tr><td class='f14' nowrap>分类:</td>";
content += "<td class='f14'><select id='spBlogCatName' name='spBlogCatName' style='width:90px' >";
content += "<option value='默认分类'>默认分类</option>";
content += "< lect></td></tr>";
content += "<tr><td class='f14' nowrap>评论:</td><td class='f14'><input name='spIsCmtAllow' type='radio' value='1' checked='checked' >允许 <input name='spIsCmtAllow' type='radio' value='0'>禁止</td>";
content += "</tr><tr><td class='f14' nowrap>状态:</td><td><select name='spBlogPower' style='width:90px' ><option value='0' >公开</option><option value='1'>仅向好友开放</option><option value='3'>私有</option>< lect></td>";
content += "<input type='hidden' name='tpl' value='sp'>";
content += "</tr><tr><td> </td><td class='formsb'><input name='tj' type='button' value=' 发表文章 ' ></td></tr></table></div></form>";
content += "<td >结果返回<input type='text' name='loading' id='loading' style='width:540px' value='' onChange=''></td>";
content += "</body></html>";
$(main).innerHTML = content;
var edit = new editor("spBlogText", "sfsdf");
$("tj").onclick = function submit_Button(){
form1.spBlogText.value= edit.gettxt();
var actionurl=document.all("posturl");
if(actionurl.value==""){
alert("提交的空间地址不能为空");
return false;}
if(actionurl.value.replace("hi.baidu.com/")==actionurl.value){
alert("地址错误,请输入您的百度空间地址");
return false;}
else
{
form1.action=actionurl.value +"/commit";
}
ajaxSubmitForm(form1);
}
}
function ajaxSubmitForm(form) {
var elements = form.elements;// Enumeration the form elements
var element;
var i;
var postContent = "";// Form contents need to submit
for(i=0;i<elements.length;++i) {
var element=elements[i];
if(element.name==""||element.name==null||element.type=="")
continue;
if(element.type=="text" || element.type=="textarea" || element.type=="hidden"||element.type=="password") {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
else if(element.type=="select-one"||element.type=="select-multiple") {
var options=element.options,j,item;
for(j=0;j<options.length;++j){
item=options[j];
if(item.selected) {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(item.value) + "&";
}
}
} else if(element.type=="checkbox"||element.type=="radio") {
if(element.checked) {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
} else if(element.type=="file") {
if(element.value != "") {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
}
else {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
}
ajaxSubmit(form.action, form.method, postContent);
}
function ajaxSubmit(url, method, postContent)
{
var loadingDiv = document.getElementById('loading');
// call in new thread to allow ui to update
window.setTimeout(function () {
loadingDiv.innerText = "Loading....";
loadingDiv.style.display = "";
}, 1);
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
// code for IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if(xmlhttp) {
xmlhttp.onreadystatechange = function() {
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
{
if(xmlhttp.status==200) {
var result = document.createElement("DIV");
result.style.border="5px solid #363636";
result.innerHTML = xmlhttp.responseText;
document.body.appendChild(result);
} else {
var result = document.createElement("DIV");
result.style.border="1px solid #363636";
result.innerHTML = xmlhttp.responseText;
document.body.appendChild(result);
}
loadingDiv.innerText = "Submit finnished!";
}
};
if(method.toLowerCase() == "get") {
xmlhttp.open("GET", url + "?" + postContent, true);
setRequestHeader("Content-Type","text/html; encoding=gb2312");
xmlhttp.send(null);
} else if(method.toLowerCase() == "post") {
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=gb2312");
xmlhttp.send(postContent);
}
} else {
loadingDiv.innerHTML =
"Can't create XMLHttpRequest object, please check your web browser.";
}
}
content += "<head><meta http-equiv='Content-TYPE' content=text/html; charset=gb2312>";
content += "<body >";
content += "<input type='text' name='posturl' value='' style='width:300px; border:1px solid #006699'>形式如:";
content += "<form name='form1' id='popFormSubmit' action='a.jsp' target='_blank' method='post' style='border:0px; padding:0px; margin:0px;'>";
content += "<input type='hidden' name='ct' value='1'/>";
content += "<input type='hidden' name='cm' value='1'/>";
content += "<div id='m_blognew' class='modbox''>";
content += "<table border='0' cellspacing='6' cellpadding='3' class='formhd' width='90%' bgcolor='#ffffff' align='center'>";
content += "<tr><td width='60' class='f14' nowrap>标题:</td>";
content += "<td><input type='text' name='spBlogTitle' id='spBlogTitle' style='width:540px' value='uuuuuuuuuuu' onChange=''></td>";
content += "<tr><td width='60' class='f14' nowrap>内容: <td><div id='spBlogText'></div><input type='hidden' name='spBlogText' /></td></tr>";
content += "<tr><td class='f14' nowrap>分类:</td>";
content += "<td class='f14'><select id='spBlogCatName' name='spBlogCatName' style='width:90px' >";
content += "<option value='默认分类'>默认分类</option>";
content += "< lect></td></tr>";
content += "<tr><td class='f14' nowrap>评论:</td><td class='f14'><input name='spIsCmtAllow' type='radio' value='1' checked='checked' >允许 <input name='spIsCmtAllow' type='radio' value='0'>禁止</td>";
content += "</tr><tr><td class='f14' nowrap>状态:</td><td><select name='spBlogPower' style='width:90px' ><option value='0' >公开</option><option value='1'>仅向好友开放</option><option value='3'>私有</option>< lect></td>";
content += "<input type='hidden' name='tpl' value='sp'>";
content += "</tr><tr><td> </td><td class='formsb'><input name='tj' type='button' value=' 发表文章 ' ></td></tr></table></div></form>";
content += "<td >结果返回<input type='text' name='loading' id='loading' style='width:540px' value='' onChange=''></td>";
content += "</body></html>";
$(main).innerHTML = content;
var edit = new editor("spBlogText", "sfsdf");
$("tj").onclick = function submit_Button(){
form1.spBlogText.value= edit.gettxt();
var actionurl=document.all("posturl");
if(actionurl.value==""){
alert("提交的空间地址不能为空");
return false;}
if(actionurl.value.replace("hi.baidu.com/")==actionurl.value){
alert("地址错误,请输入您的百度空间地址");
return false;}
else
{
form1.action=actionurl.value +"/commit";
}
ajaxSubmitForm(form1);
}
}
function ajaxSubmitForm(form) {
var elements = form.elements;// Enumeration the form elements
var element;
var i;
var postContent = "";// Form contents need to submit
for(i=0;i<elements.length;++i) {
var element=elements[i];
if(element.name==""||element.name==null||element.type=="")
continue;
if(element.type=="text" || element.type=="textarea" || element.type=="hidden"||element.type=="password") {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
else if(element.type=="select-one"||element.type=="select-multiple") {
var options=element.options,j,item;
for(j=0;j<options.length;++j){
item=options[j];
if(item.selected) {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(item.value) + "&";
}
}
} else if(element.type=="checkbox"||element.type=="radio") {
if(element.checked) {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
} else if(element.type=="file") {
if(element.value != "") {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
}
else {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
}
ajaxSubmit(form.action, form.method, postContent);
}
function ajaxSubmit(url, method, postContent)
{
var loadingDiv = document.getElementById('loading');
// call in new thread to allow ui to update
window.setTimeout(function () {
loadingDiv.innerText = "Loading....";
loadingDiv.style.display = "";
}, 1);
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
// code for IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if(xmlhttp) {
xmlhttp.onreadystatechange = function() {
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
{
if(xmlhttp.status==200) {
var result = document.createElement("DIV");
result.style.border="5px solid #363636";
result.innerHTML = xmlhttp.responseText;
document.body.appendChild(result);
} else {
var result = document.createElement("DIV");
result.style.border="1px solid #363636";
result.innerHTML = xmlhttp.responseText;
document.body.appendChild(result);
}
loadingDiv.innerText = "Submit finnished!";
}
};
if(method.toLowerCase() == "get") {
xmlhttp.open("GET", url + "?" + postContent, true);
setRequestHeader("Content-Type","text/html; encoding=gb2312");
xmlhttp.send(null);
} else if(method.toLowerCase() == "post") {
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=gb2312");
xmlhttp.send(postContent);
}
} else {
loadingDiv.innerHTML =
"Can't create XMLHttpRequest object, please check your web browser.";
}
}
#4
用form直接action是没遇问题的
用form的action方式是中文 没问题的 但是用ajax就是乱码
用form的action方式是中文 没问题的 但是用ajax就是乱码
#5
String str = new String("字符串".getBytes(),"gbk");
这样试试看转的过来。
这样试试看转的过来。
#6
编码问题
#7
ajax中文问题 可以使用过滤器解决
#8
1、在使用"GET"时,抓取的页面最后加上编码类型
<%
Response.Expires = -9999
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-ctrol","no-cache"
Response.AddHeader "Content-Type","text/html; charset=gb2312"‘这是重点,否则会出现乱码
Response.write "中文汉字"%>
2、在使用Post时用VBscript解决了编码问题:
源码如下:
<script language="VBScript">
Function URLEncoding(vstrIn)
strReturn = ""
For i = 1 To Len(vstrIn)
ThisChr = Mid(vStrIn,i,1)
If Abs(Asc(ThisChr)) < &HFF Then
strReturn = strReturn & ThisChr
Else
innerCode = Asc(ThisChr)
If innerCode < 0 Then
innerCode = innerCode + &H10000
End If
Hight8 = (innerCode And &HFF00)\ &HFF
Low8 = innerCode And &HFF
strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
End If
Next
URLEncoding = strReturn
End Function
Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
</script>
下面是使用VBScript函数:
<script language=javascript>
/**
* 初始化一个xmlhttp对象
*/
function InitAjax()
{
var ajax=false;
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = false;
}
}
if (!ajax && typeof XMLHttpRequest!='undefined') {
ajax = new XMLHttpRequest();
}
return ajax;
}
function saveUserInfo()
{
var msg = document.getElementById("msg");
var f = document.user_info;
var userName = f.user_name.value;
var userAge = f.user_age.value;
var userSex = f.user_sex.value;
var url = "save.asp";
var postStr = URLEncoding("user_name="+ userName +"&user_age="+ userAge +"&user_sex="+ userSex);//Post时采用编码传递
var ajax = InitAjax();
ajax.open("POST", url, true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(postStr);
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 && ajax.status == 200) {
msg.innerHTML = bytes2BSTR(ajax.responseBody); //获取时解码
}
}
}
</script>
<form name="user_info">
姓名:<textarea name="user_name" /></textarea><br />
年龄:<input type="text" name="user_age" /><br />
性别:<input type="text" name="user_sex" /><br />
<input type="button" value="提交表单" onClick="saveUserInfo()">
</form>
<div id="msg"></div>
成功
<%
Response.Expires = -9999
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-ctrol","no-cache"
Response.AddHeader "Content-Type","text/html; charset=gb2312"‘这是重点,否则会出现乱码
Response.write "中文汉字"%>
2、在使用Post时用VBscript解决了编码问题:
源码如下:
<script language="VBScript">
Function URLEncoding(vstrIn)
strReturn = ""
For i = 1 To Len(vstrIn)
ThisChr = Mid(vStrIn,i,1)
If Abs(Asc(ThisChr)) < &HFF Then
strReturn = strReturn & ThisChr
Else
innerCode = Asc(ThisChr)
If innerCode < 0 Then
innerCode = innerCode + &H10000
End If
Hight8 = (innerCode And &HFF00)\ &HFF
Low8 = innerCode And &HFF
strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
End If
Next
URLEncoding = strReturn
End Function
Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
</script>
下面是使用VBScript函数:
<script language=javascript>
/**
* 初始化一个xmlhttp对象
*/
function InitAjax()
{
var ajax=false;
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = false;
}
}
if (!ajax && typeof XMLHttpRequest!='undefined') {
ajax = new XMLHttpRequest();
}
return ajax;
}
function saveUserInfo()
{
var msg = document.getElementById("msg");
var f = document.user_info;
var userName = f.user_name.value;
var userAge = f.user_age.value;
var userSex = f.user_sex.value;
var url = "save.asp";
var postStr = URLEncoding("user_name="+ userName +"&user_age="+ userAge +"&user_sex="+ userSex);//Post时采用编码传递
var ajax = InitAjax();
ajax.open("POST", url, true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(postStr);
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 && ajax.status == 200) {
msg.innerHTML = bytes2BSTR(ajax.responseBody); //获取时解码
}
}
}
</script>
<form name="user_info">
姓名:<textarea name="user_name" /></textarea><br />
年龄:<input type="text" name="user_age" /><br />
性别:<input type="text" name="user_sex" /><br />
<input type="button" value="提交表单" onClick="saveUserInfo()">
</form>
<div id="msg"></div>
成功
#9
将ajax发送的内容用javascript中escape过滤一下应该就没什么问题了!如果ajax发送content,则content=escape(content)
#10
xmlHttp.open("POST",url, true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.send("Name=" + encodeURIComponent(node.value));//发送包含用户输入信息的请求体
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.send("Name=" + encodeURIComponent(node.value));//发送包含用户输入信息的请求体
#11
用utf -8的编码,在解码出来
#12
设计ajax文件的编码,使用dreamweaver在页面属性里设置,使用myeclipse也是右键设置编码和jsp文件统一
#13
后台程序:response.write (escape(str))
页面文件:var strResult =unescape(oBao.responseText);
基本可以解决编码问题
页面文件:var strResult =unescape(oBao.responseText);
基本可以解决编码问题
#14
发送前escape()一下就ok了
#15
接收的地方解码一下呀
#16
content=
escape(content)
#17
服务器端输出请写上 Response.CharSet="gb2312"
提交数据使请使用 escape 服务端返回unescape
提交数据使请使用 escape 服务端返回unescape
#18
$(main).innerHTML=
escape(content)
#19
Ajax,关注中!
#20
看看这个,一定有用
AJAX中文问题分为两大类:
1)发送路径中的参数有中文,在服务器段接收参数值是乱码
例如:
var url="a.jsp?name=小李";
xmlHTTP.open ("post",url,true);
解决办法:
利用javascript的提供的escape()或encodeURI()方法
例如:
客户端:
var url="a.jsp?name=小李";
url=encodeURI(url);
url=encodeURI(url); //两次,很关键[具体为什么,我也不清楚]
/********************************************/
也有人写成var url="a.jsp?name=escape("小李")";
功能和encodeURI方法类似。
/********************************************/
xmlHTTP.setrequestheader("cache-control","no-cache");
xmlHTTP.setrequestheader("Content-Type","application/x-www-form-urlencoded");
xmlHTTP.setrequestheader("contentType","text/html;charset=uft-8")//指定发送数据的编码格式
xmlHTTP.open ("post",url,true);
服务器端:
String name = request.getParameter("name");
name = java.net.URLDecoder.decode("name", "UTF-8");
2)返回来的responseText或responseXML的值中含有中文是乱码
原因:AJAX在接收responseText或responseXML的值的时候是按照UTF-8的格式来解码的,如果服务器段发送的数据不是UTF-8的格式,那么接收responseText或responseXML的值有可能为乱码。
解决办法:在服务器指定发送数据的格式:
在jsp文件中:
response.setContentType("text/text;charset=UTF-8");//返回的是txt文本文件
或是
response.setContentType("text/xml;charset=UTF-8");//返回的xml文件
总结:
1)ajax提交数据的格式默认为utf-8,利用javascript的提供的escape()或encodeURI()方法.在服务器端接收的时候要使用java.net.URLDecoder.decode("","UTF-8")方法进行解码.
2)xtmlhttp 返回的数据默认的字符编码是utf-8,所以服务器要向客户端发送数据的时候,也要采用utf-8编码.如果上述方法仍然解决不了乱码问题,那你尝试一下把jsp,htm,java文件用UTF-8编码格式保存.
总之:前后台数据交互都采用utf-8编码就行了.
AJAX中文问题分为两大类:
1)发送路径中的参数有中文,在服务器段接收参数值是乱码
例如:
var url="a.jsp?name=小李";
xmlHTTP.open ("post",url,true);
解决办法:
利用javascript的提供的escape()或encodeURI()方法
例如:
客户端:
var url="a.jsp?name=小李";
url=encodeURI(url);
url=encodeURI(url); //两次,很关键[具体为什么,我也不清楚]
/********************************************/
也有人写成var url="a.jsp?name=escape("小李")";
功能和encodeURI方法类似。
/********************************************/
xmlHTTP.setrequestheader("cache-control","no-cache");
xmlHTTP.setrequestheader("Content-Type","application/x-www-form-urlencoded");
xmlHTTP.setrequestheader("contentType","text/html;charset=uft-8")//指定发送数据的编码格式
xmlHTTP.open ("post",url,true);
服务器端:
String name = request.getParameter("name");
name = java.net.URLDecoder.decode("name", "UTF-8");
2)返回来的responseText或responseXML的值中含有中文是乱码
原因:AJAX在接收responseText或responseXML的值的时候是按照UTF-8的格式来解码的,如果服务器段发送的数据不是UTF-8的格式,那么接收responseText或responseXML的值有可能为乱码。
解决办法:在服务器指定发送数据的格式:
在jsp文件中:
response.setContentType("text/text;charset=UTF-8");//返回的是txt文本文件
或是
response.setContentType("text/xml;charset=UTF-8");//返回的xml文件
总结:
1)ajax提交数据的格式默认为utf-8,利用javascript的提供的escape()或encodeURI()方法.在服务器端接收的时候要使用java.net.URLDecoder.decode("","UTF-8")方法进行解码.
2)xtmlhttp 返回的数据默认的字符编码是utf-8,所以服务器要向客户端发送数据的时候,也要采用utf-8编码.如果上述方法仍然解决不了乱码问题,那你尝试一下把jsp,htm,java文件用UTF-8编码格式保存.
总之:前后台数据交互都采用utf-8编码就行了.
#21
MARK.
#22
我的是ASP页面,解决方式是这样的。奶奶地,当时这个问题困扰了我一天时间!!!测试过了,一点问题没有!希望你也能测成功!
js 块
var sBody= encodeURI(encodeURI(oForm.reinfo.value));
url=url+"&timeStamp="+new Date().getTime()+"&n="+Math.random();
xmlHttp.open("post",url,true);
xmlHttp.setRequestHeader("Cache-Control","no-cache");
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gb2312");
xmlHttp.onreadystatechange=updatePage;
xmlHttp.send(sBody);
处理页面
response.clear()
response.Charset="gb2312"
reinfo=decodeText(trim(request("reinfo")))
<script language="javascript" runat="server">
function decodeText(str){
return(str== null?"":decodeURIComponent(str));
}
</script>
js 块
var sBody= encodeURI(encodeURI(oForm.reinfo.value));
url=url+"&timeStamp="+new Date().getTime()+"&n="+Math.random();
xmlHttp.open("post",url,true);
xmlHttp.setRequestHeader("Cache-Control","no-cache");
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gb2312");
xmlHttp.onreadystatechange=updatePage;
xmlHttp.send(sBody);
处理页面
response.clear()
response.Charset="gb2312"
reinfo=decodeText(trim(request("reinfo")))
<script language="javascript" runat="server">
function decodeText(str){
return(str== null?"":decodeURIComponent(str));
}
</script>
#23
用escape(),服务器端编码要和客户端一样
注意以下加号,可能会丢掉,需要在escape前先变为%2b
注意以下加号,可能会丢掉,需要在escape前先变为%2b
#1
我可以看看你ajax post的URL代码么?
#2
jsp页上面就要设置 本页输出编码是gb2312
#3
var content = " <html xmlns='http://www.w3.org/1999/xhtml'>";
content += "<head><meta http-equiv='Content-TYPE' content=text/html; charset=gb2312>";
content += "<body >";
content += "<input type='text' name='posturl' value='' style='width:300px; border:1px solid #006699'>形式如:";
content += "<form name='form1' id='popFormSubmit' action='a.jsp' target='_blank' method='post' style='border:0px; padding:0px; margin:0px;'>";
content += "<input type='hidden' name='ct' value='1'/>";
content += "<input type='hidden' name='cm' value='1'/>";
content += "<div id='m_blognew' class='modbox''>";
content += "<table border='0' cellspacing='6' cellpadding='3' class='formhd' width='90%' bgcolor='#ffffff' align='center'>";
content += "<tr><td width='60' class='f14' nowrap>标题:</td>";
content += "<td><input type='text' name='spBlogTitle' id='spBlogTitle' style='width:540px' value='uuuuuuuuuuu' onChange=''></td>";
content += "<tr><td width='60' class='f14' nowrap>内容: <td><div id='spBlogText'></div><input type='hidden' name='spBlogText' /></td></tr>";
content += "<tr><td class='f14' nowrap>分类:</td>";
content += "<td class='f14'><select id='spBlogCatName' name='spBlogCatName' style='width:90px' >";
content += "<option value='默认分类'>默认分类</option>";
content += "< lect></td></tr>";
content += "<tr><td class='f14' nowrap>评论:</td><td class='f14'><input name='spIsCmtAllow' type='radio' value='1' checked='checked' >允许 <input name='spIsCmtAllow' type='radio' value='0'>禁止</td>";
content += "</tr><tr><td class='f14' nowrap>状态:</td><td><select name='spBlogPower' style='width:90px' ><option value='0' >公开</option><option value='1'>仅向好友开放</option><option value='3'>私有</option>< lect></td>";
content += "<input type='hidden' name='tpl' value='sp'>";
content += "</tr><tr><td> </td><td class='formsb'><input name='tj' type='button' value=' 发表文章 ' ></td></tr></table></div></form>";
content += "<td >结果返回<input type='text' name='loading' id='loading' style='width:540px' value='' onChange=''></td>";
content += "</body></html>";
$(main).innerHTML = content;
var edit = new editor("spBlogText", "sfsdf");
$("tj").onclick = function submit_Button(){
form1.spBlogText.value= edit.gettxt();
var actionurl=document.all("posturl");
if(actionurl.value==""){
alert("提交的空间地址不能为空");
return false;}
if(actionurl.value.replace("hi.baidu.com/")==actionurl.value){
alert("地址错误,请输入您的百度空间地址");
return false;}
else
{
form1.action=actionurl.value +"/commit";
}
ajaxSubmitForm(form1);
}
}
function ajaxSubmitForm(form) {
var elements = form.elements;// Enumeration the form elements
var element;
var i;
var postContent = "";// Form contents need to submit
for(i=0;i<elements.length;++i) {
var element=elements[i];
if(element.name==""||element.name==null||element.type=="")
continue;
if(element.type=="text" || element.type=="textarea" || element.type=="hidden"||element.type=="password") {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
else if(element.type=="select-one"||element.type=="select-multiple") {
var options=element.options,j,item;
for(j=0;j<options.length;++j){
item=options[j];
if(item.selected) {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(item.value) + "&";
}
}
} else if(element.type=="checkbox"||element.type=="radio") {
if(element.checked) {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
} else if(element.type=="file") {
if(element.value != "") {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
}
else {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
}
ajaxSubmit(form.action, form.method, postContent);
}
function ajaxSubmit(url, method, postContent)
{
var loadingDiv = document.getElementById('loading');
// call in new thread to allow ui to update
window.setTimeout(function () {
loadingDiv.innerText = "Loading....";
loadingDiv.style.display = "";
}, 1);
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
// code for IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if(xmlhttp) {
xmlhttp.onreadystatechange = function() {
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
{
if(xmlhttp.status==200) {
var result = document.createElement("DIV");
result.style.border="5px solid #363636";
result.innerHTML = xmlhttp.responseText;
document.body.appendChild(result);
} else {
var result = document.createElement("DIV");
result.style.border="1px solid #363636";
result.innerHTML = xmlhttp.responseText;
document.body.appendChild(result);
}
loadingDiv.innerText = "Submit finnished!";
}
};
if(method.toLowerCase() == "get") {
xmlhttp.open("GET", url + "?" + postContent, true);
setRequestHeader("Content-Type","text/html; encoding=gb2312");
xmlhttp.send(null);
} else if(method.toLowerCase() == "post") {
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=gb2312");
xmlhttp.send(postContent);
}
} else {
loadingDiv.innerHTML =
"Can't create XMLHttpRequest object, please check your web browser.";
}
}
content += "<head><meta http-equiv='Content-TYPE' content=text/html; charset=gb2312>";
content += "<body >";
content += "<input type='text' name='posturl' value='' style='width:300px; border:1px solid #006699'>形式如:";
content += "<form name='form1' id='popFormSubmit' action='a.jsp' target='_blank' method='post' style='border:0px; padding:0px; margin:0px;'>";
content += "<input type='hidden' name='ct' value='1'/>";
content += "<input type='hidden' name='cm' value='1'/>";
content += "<div id='m_blognew' class='modbox''>";
content += "<table border='0' cellspacing='6' cellpadding='3' class='formhd' width='90%' bgcolor='#ffffff' align='center'>";
content += "<tr><td width='60' class='f14' nowrap>标题:</td>";
content += "<td><input type='text' name='spBlogTitle' id='spBlogTitle' style='width:540px' value='uuuuuuuuuuu' onChange=''></td>";
content += "<tr><td width='60' class='f14' nowrap>内容: <td><div id='spBlogText'></div><input type='hidden' name='spBlogText' /></td></tr>";
content += "<tr><td class='f14' nowrap>分类:</td>";
content += "<td class='f14'><select id='spBlogCatName' name='spBlogCatName' style='width:90px' >";
content += "<option value='默认分类'>默认分类</option>";
content += "< lect></td></tr>";
content += "<tr><td class='f14' nowrap>评论:</td><td class='f14'><input name='spIsCmtAllow' type='radio' value='1' checked='checked' >允许 <input name='spIsCmtAllow' type='radio' value='0'>禁止</td>";
content += "</tr><tr><td class='f14' nowrap>状态:</td><td><select name='spBlogPower' style='width:90px' ><option value='0' >公开</option><option value='1'>仅向好友开放</option><option value='3'>私有</option>< lect></td>";
content += "<input type='hidden' name='tpl' value='sp'>";
content += "</tr><tr><td> </td><td class='formsb'><input name='tj' type='button' value=' 发表文章 ' ></td></tr></table></div></form>";
content += "<td >结果返回<input type='text' name='loading' id='loading' style='width:540px' value='' onChange=''></td>";
content += "</body></html>";
$(main).innerHTML = content;
var edit = new editor("spBlogText", "sfsdf");
$("tj").onclick = function submit_Button(){
form1.spBlogText.value= edit.gettxt();
var actionurl=document.all("posturl");
if(actionurl.value==""){
alert("提交的空间地址不能为空");
return false;}
if(actionurl.value.replace("hi.baidu.com/")==actionurl.value){
alert("地址错误,请输入您的百度空间地址");
return false;}
else
{
form1.action=actionurl.value +"/commit";
}
ajaxSubmitForm(form1);
}
}
function ajaxSubmitForm(form) {
var elements = form.elements;// Enumeration the form elements
var element;
var i;
var postContent = "";// Form contents need to submit
for(i=0;i<elements.length;++i) {
var element=elements[i];
if(element.name==""||element.name==null||element.type=="")
continue;
if(element.type=="text" || element.type=="textarea" || element.type=="hidden"||element.type=="password") {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
else if(element.type=="select-one"||element.type=="select-multiple") {
var options=element.options,j,item;
for(j=0;j<options.length;++j){
item=options[j];
if(item.selected) {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(item.value) + "&";
}
}
} else if(element.type=="checkbox"||element.type=="radio") {
if(element.checked) {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
} else if(element.type=="file") {
if(element.value != "") {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
}
else {
postContent += encodeURIComponent(element.name) + "=" + encodeURIComponent(element.value) + "&";
}
}
ajaxSubmit(form.action, form.method, postContent);
}
function ajaxSubmit(url, method, postContent)
{
var loadingDiv = document.getElementById('loading');
// call in new thread to allow ui to update
window.setTimeout(function () {
loadingDiv.innerText = "Loading....";
loadingDiv.style.display = "";
}, 1);
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
// code for IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if(xmlhttp) {
xmlhttp.onreadystatechange = function() {
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
{
if(xmlhttp.status==200) {
var result = document.createElement("DIV");
result.style.border="5px solid #363636";
result.innerHTML = xmlhttp.responseText;
document.body.appendChild(result);
} else {
var result = document.createElement("DIV");
result.style.border="1px solid #363636";
result.innerHTML = xmlhttp.responseText;
document.body.appendChild(result);
}
loadingDiv.innerText = "Submit finnished!";
}
};
if(method.toLowerCase() == "get") {
xmlhttp.open("GET", url + "?" + postContent, true);
setRequestHeader("Content-Type","text/html; encoding=gb2312");
xmlhttp.send(null);
} else if(method.toLowerCase() == "post") {
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=gb2312");
xmlhttp.send(postContent);
}
} else {
loadingDiv.innerHTML =
"Can't create XMLHttpRequest object, please check your web browser.";
}
}
#4
用form直接action是没遇问题的
用form的action方式是中文 没问题的 但是用ajax就是乱码
用form的action方式是中文 没问题的 但是用ajax就是乱码
#5
String str = new String("字符串".getBytes(),"gbk");
这样试试看转的过来。
这样试试看转的过来。
#6
编码问题
#7
ajax中文问题 可以使用过滤器解决
#8
1、在使用"GET"时,抓取的页面最后加上编码类型
<%
Response.Expires = -9999
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-ctrol","no-cache"
Response.AddHeader "Content-Type","text/html; charset=gb2312"‘这是重点,否则会出现乱码
Response.write "中文汉字"%>
2、在使用Post时用VBscript解决了编码问题:
源码如下:
<script language="VBScript">
Function URLEncoding(vstrIn)
strReturn = ""
For i = 1 To Len(vstrIn)
ThisChr = Mid(vStrIn,i,1)
If Abs(Asc(ThisChr)) < &HFF Then
strReturn = strReturn & ThisChr
Else
innerCode = Asc(ThisChr)
If innerCode < 0 Then
innerCode = innerCode + &H10000
End If
Hight8 = (innerCode And &HFF00)\ &HFF
Low8 = innerCode And &HFF
strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
End If
Next
URLEncoding = strReturn
End Function
Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
</script>
下面是使用VBScript函数:
<script language=javascript>
/**
* 初始化一个xmlhttp对象
*/
function InitAjax()
{
var ajax=false;
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = false;
}
}
if (!ajax && typeof XMLHttpRequest!='undefined') {
ajax = new XMLHttpRequest();
}
return ajax;
}
function saveUserInfo()
{
var msg = document.getElementById("msg");
var f = document.user_info;
var userName = f.user_name.value;
var userAge = f.user_age.value;
var userSex = f.user_sex.value;
var url = "save.asp";
var postStr = URLEncoding("user_name="+ userName +"&user_age="+ userAge +"&user_sex="+ userSex);//Post时采用编码传递
var ajax = InitAjax();
ajax.open("POST", url, true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(postStr);
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 && ajax.status == 200) {
msg.innerHTML = bytes2BSTR(ajax.responseBody); //获取时解码
}
}
}
</script>
<form name="user_info">
姓名:<textarea name="user_name" /></textarea><br />
年龄:<input type="text" name="user_age" /><br />
性别:<input type="text" name="user_sex" /><br />
<input type="button" value="提交表单" onClick="saveUserInfo()">
</form>
<div id="msg"></div>
成功
<%
Response.Expires = -9999
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-ctrol","no-cache"
Response.AddHeader "Content-Type","text/html; charset=gb2312"‘这是重点,否则会出现乱码
Response.write "中文汉字"%>
2、在使用Post时用VBscript解决了编码问题:
源码如下:
<script language="VBScript">
Function URLEncoding(vstrIn)
strReturn = ""
For i = 1 To Len(vstrIn)
ThisChr = Mid(vStrIn,i,1)
If Abs(Asc(ThisChr)) < &HFF Then
strReturn = strReturn & ThisChr
Else
innerCode = Asc(ThisChr)
If innerCode < 0 Then
innerCode = innerCode + &H10000
End If
Hight8 = (innerCode And &HFF00)\ &HFF
Low8 = innerCode And &HFF
strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
End If
Next
URLEncoding = strReturn
End Function
Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
</script>
下面是使用VBScript函数:
<script language=javascript>
/**
* 初始化一个xmlhttp对象
*/
function InitAjax()
{
var ajax=false;
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = false;
}
}
if (!ajax && typeof XMLHttpRequest!='undefined') {
ajax = new XMLHttpRequest();
}
return ajax;
}
function saveUserInfo()
{
var msg = document.getElementById("msg");
var f = document.user_info;
var userName = f.user_name.value;
var userAge = f.user_age.value;
var userSex = f.user_sex.value;
var url = "save.asp";
var postStr = URLEncoding("user_name="+ userName +"&user_age="+ userAge +"&user_sex="+ userSex);//Post时采用编码传递
var ajax = InitAjax();
ajax.open("POST", url, true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(postStr);
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 && ajax.status == 200) {
msg.innerHTML = bytes2BSTR(ajax.responseBody); //获取时解码
}
}
}
</script>
<form name="user_info">
姓名:<textarea name="user_name" /></textarea><br />
年龄:<input type="text" name="user_age" /><br />
性别:<input type="text" name="user_sex" /><br />
<input type="button" value="提交表单" onClick="saveUserInfo()">
</form>
<div id="msg"></div>
成功
#9
将ajax发送的内容用javascript中escape过滤一下应该就没什么问题了!如果ajax发送content,则content=escape(content)
#10
xmlHttp.open("POST",url, true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.send("Name=" + encodeURIComponent(node.value));//发送包含用户输入信息的请求体
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.send("Name=" + encodeURIComponent(node.value));//发送包含用户输入信息的请求体
#11
用utf -8的编码,在解码出来
#12
设计ajax文件的编码,使用dreamweaver在页面属性里设置,使用myeclipse也是右键设置编码和jsp文件统一
#13
后台程序:response.write (escape(str))
页面文件:var strResult =unescape(oBao.responseText);
基本可以解决编码问题
页面文件:var strResult =unescape(oBao.responseText);
基本可以解决编码问题
#14
发送前escape()一下就ok了
#15
接收的地方解码一下呀
#16
content=
escape(content)
#17
服务器端输出请写上 Response.CharSet="gb2312"
提交数据使请使用 escape 服务端返回unescape
提交数据使请使用 escape 服务端返回unescape
#18
$(main).innerHTML=
escape(content)
#19
Ajax,关注中!
#20
看看这个,一定有用
AJAX中文问题分为两大类:
1)发送路径中的参数有中文,在服务器段接收参数值是乱码
例如:
var url="a.jsp?name=小李";
xmlHTTP.open ("post",url,true);
解决办法:
利用javascript的提供的escape()或encodeURI()方法
例如:
客户端:
var url="a.jsp?name=小李";
url=encodeURI(url);
url=encodeURI(url); //两次,很关键[具体为什么,我也不清楚]
/********************************************/
也有人写成var url="a.jsp?name=escape("小李")";
功能和encodeURI方法类似。
/********************************************/
xmlHTTP.setrequestheader("cache-control","no-cache");
xmlHTTP.setrequestheader("Content-Type","application/x-www-form-urlencoded");
xmlHTTP.setrequestheader("contentType","text/html;charset=uft-8")//指定发送数据的编码格式
xmlHTTP.open ("post",url,true);
服务器端:
String name = request.getParameter("name");
name = java.net.URLDecoder.decode("name", "UTF-8");
2)返回来的responseText或responseXML的值中含有中文是乱码
原因:AJAX在接收responseText或responseXML的值的时候是按照UTF-8的格式来解码的,如果服务器段发送的数据不是UTF-8的格式,那么接收responseText或responseXML的值有可能为乱码。
解决办法:在服务器指定发送数据的格式:
在jsp文件中:
response.setContentType("text/text;charset=UTF-8");//返回的是txt文本文件
或是
response.setContentType("text/xml;charset=UTF-8");//返回的xml文件
总结:
1)ajax提交数据的格式默认为utf-8,利用javascript的提供的escape()或encodeURI()方法.在服务器端接收的时候要使用java.net.URLDecoder.decode("","UTF-8")方法进行解码.
2)xtmlhttp 返回的数据默认的字符编码是utf-8,所以服务器要向客户端发送数据的时候,也要采用utf-8编码.如果上述方法仍然解决不了乱码问题,那你尝试一下把jsp,htm,java文件用UTF-8编码格式保存.
总之:前后台数据交互都采用utf-8编码就行了.
AJAX中文问题分为两大类:
1)发送路径中的参数有中文,在服务器段接收参数值是乱码
例如:
var url="a.jsp?name=小李";
xmlHTTP.open ("post",url,true);
解决办法:
利用javascript的提供的escape()或encodeURI()方法
例如:
客户端:
var url="a.jsp?name=小李";
url=encodeURI(url);
url=encodeURI(url); //两次,很关键[具体为什么,我也不清楚]
/********************************************/
也有人写成var url="a.jsp?name=escape("小李")";
功能和encodeURI方法类似。
/********************************************/
xmlHTTP.setrequestheader("cache-control","no-cache");
xmlHTTP.setrequestheader("Content-Type","application/x-www-form-urlencoded");
xmlHTTP.setrequestheader("contentType","text/html;charset=uft-8")//指定发送数据的编码格式
xmlHTTP.open ("post",url,true);
服务器端:
String name = request.getParameter("name");
name = java.net.URLDecoder.decode("name", "UTF-8");
2)返回来的responseText或responseXML的值中含有中文是乱码
原因:AJAX在接收responseText或responseXML的值的时候是按照UTF-8的格式来解码的,如果服务器段发送的数据不是UTF-8的格式,那么接收responseText或responseXML的值有可能为乱码。
解决办法:在服务器指定发送数据的格式:
在jsp文件中:
response.setContentType("text/text;charset=UTF-8");//返回的是txt文本文件
或是
response.setContentType("text/xml;charset=UTF-8");//返回的xml文件
总结:
1)ajax提交数据的格式默认为utf-8,利用javascript的提供的escape()或encodeURI()方法.在服务器端接收的时候要使用java.net.URLDecoder.decode("","UTF-8")方法进行解码.
2)xtmlhttp 返回的数据默认的字符编码是utf-8,所以服务器要向客户端发送数据的时候,也要采用utf-8编码.如果上述方法仍然解决不了乱码问题,那你尝试一下把jsp,htm,java文件用UTF-8编码格式保存.
总之:前后台数据交互都采用utf-8编码就行了.
#21
MARK.
#22
我的是ASP页面,解决方式是这样的。奶奶地,当时这个问题困扰了我一天时间!!!测试过了,一点问题没有!希望你也能测成功!
js 块
var sBody= encodeURI(encodeURI(oForm.reinfo.value));
url=url+"&timeStamp="+new Date().getTime()+"&n="+Math.random();
xmlHttp.open("post",url,true);
xmlHttp.setRequestHeader("Cache-Control","no-cache");
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gb2312");
xmlHttp.onreadystatechange=updatePage;
xmlHttp.send(sBody);
处理页面
response.clear()
response.Charset="gb2312"
reinfo=decodeText(trim(request("reinfo")))
<script language="javascript" runat="server">
function decodeText(str){
return(str== null?"":decodeURIComponent(str));
}
</script>
js 块
var sBody= encodeURI(encodeURI(oForm.reinfo.value));
url=url+"&timeStamp="+new Date().getTime()+"&n="+Math.random();
xmlHttp.open("post",url,true);
xmlHttp.setRequestHeader("Cache-Control","no-cache");
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gb2312");
xmlHttp.onreadystatechange=updatePage;
xmlHttp.send(sBody);
处理页面
response.clear()
response.Charset="gb2312"
reinfo=decodeText(trim(request("reinfo")))
<script language="javascript" runat="server">
function decodeText(str){
return(str== null?"":decodeURIComponent(str));
}
</script>
#23
用escape(),服务器端编码要和客户端一样
注意以下加号,可能会丢掉,需要在escape前先变为%2b
注意以下加号,可能会丢掉,需要在escape前先变为%2b