Php jquery ajax html特殊字符
javascriptPhp jquery ajax html特殊字符,php,jquery,Php,Jquery,javascript var a="sadahdka sarr  " jQuery.ajax( { type:"POST", url:"function/postbai.php", dat
var a="sadahdka sarr  "
jQuery.ajax(
{
type:"POST",
url:"function/postbai.php",
data:"a="+a,
success:function(html)
{
alert(html);
}
});
以前
var a="sadahdka sarr  "
之后
为什么
帮助
jquery ajax html特殊字符,因为
&
是查询字符串中的字段分隔符。如果要保留&
请确保执行encodeURIComponent(a)代码>您的字符串作为查询字符串无效,您必须使用encodeURIComponent
对其进行编码,或者让jQuery通过传递一个对象来为您进行编码:
var data = {a :"sadahdka sarr  "};
jQuery.ajax({
type: "POST",
url: "function/postbai.php",
data: data
}).done(function (html) {
alert(html);
});
在将字符串发送到服务器之前对其进行转义,并用PHP对其进行解码
JS:
PHP:
嗨,桑吉。欢迎来到StackOverflow!如果你发现一个回答回答了你的问题,请选择它作为答案-你可以花尽可能多的时间来选择答案。请更清楚地问你的问题。不要在问题中写入标记。谢谢:()(()()()()()()()()()()()()
var data = {a :"sadahdka sarr  "};
jQuery.ajax({
type: "POST",
url: "function/postbai.php",
data: data
}).done(function (html) {
alert(html);
});
data : "a="+escape(a);
urldecode($_POST['a']);