jquery AJAX传MAP类型的参数,中文问题
是用jquery的AJAX来发送异步请求,是用MAP类型来传递参数,遇到中文的时候是乱码,具体代码如下
var dbUser = document.getElementById("dbUser").value;
var schemaObject = document.getElementById("schemaObject").value;
var appName = document.getElementById("appName").value;
var ipAddress = document.getElementById("ipAddress").value;
var timestamp = document.getElementById("timestamp").value;
var auditLevel = document.getElementById("auditLevel").value;
var dbId = document.getElementById("dbId").value;
var sqlText=document.getElementById("sqlText").value;
var map = "sqlText="+sqlText+"&dbUser=" + dbUser+"&tmpName="+tmpName+"&mail="+mail+"&schemaObject=" + schemaObject + "&appName=" + appName+ "&ipAddress="+ipAddress+"×tamp="+timestamp+"×tamp="+timestamp+"&dbId="+dbId+"&auditLevel="+auditLevel;
$.ajax({
type:"POST",
url:"",
data:map,
async:false,
success:function(data){
var infos = eval("(" + data + ")");
alert(infos["info"]);
}
});
var map = "sqlText="+sqlText+"&dbUser=" + dbUser+"&tmpName="+tmpName+"&mail="+mail+"&schemaObject=" + schemaObject + "&appName=" + appName+ "&ipAddress="+ipAddress+"×tamp="+timestamp+"×tamp="+timestamp+"&dbId="+dbId+"&auditLevel="+auditLevel;
假如sqlText有中文,那么采用data:map传参就有乱码。
办法是用escape关键字解决问题
var map = "sqlText="+escape(sqlText)+"&dbUser=" + dbUser+"&tmpName="+tmpName+"&mail="+mail+"&schemaObject=" + schemaObject + "&appName=" + appName+ "&ipAddress="+ipAddress+"×tamp="+timestamp+"×tamp="+timestamp+"&dbId="+dbId+"&auditLevel="+auditLevel;