关于jquery ajax里data有特殊字符的问题

$.ajax({
url :"funRouter!funvalidate.action",
async :false,
type :"post",
dataType :"json",
data : { parametersStr:queryxml,lotime:new Date() },
error : function(C) {
doalert("访问失败");
},
如果queryxml里有特殊字符比如&就会报错,请问这个问题怎么解决谢谢。

使用encodeURIComponent()函数包裹即可,还有,你data中的变量需要双引号引住,如下:
data : { "parametersStr":encodeURIComponent(queryxml),"lotime":encodeURIComponent(new Date())},
已经测试通过的了。
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-09-04
urlencode下再试
第2个回答  2012-09-04
data改成这样试试
data : { parametersStr:"queryxml",lotime:"new Date()" },追问

这是不行滴,queryxml是个变量,而new date()是个对象,不能当字符串使

追答

这样啊,这还真是个问题

相似回答