Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jquery ajax html特殊字符_Php_Jquery - Fatal编程技术网

Php jquery ajax html特殊字符

Php jquery ajax html特殊字符,php,jquery,Php,Jquery,javascript var a="sadahdka sarr    &nbsp" jQuery.ajax( { type:"POST", url:"function/postbai.php", dat

javascript

var a="sadahdka sarr    &nbsp"

jQuery.ajax(
                        {
                            type:"POST",
                            url:"function/postbai.php",
                            data:"a="+a,
                            success:function(html)
                            {
                                alert(html);
                            }
                        });
以前

var a="sadahdka sarr    &nbsp"
之后 为什么

帮助
jquery ajax html特殊字符

,因为
&
是查询字符串中的字段分隔符。如果要保留
&
请确保执行
encodeURIComponent(a)

您的字符串作为查询字符串无效,您必须使用
encodeURIComponent
对其进行编码,或者让jQuery通过传递一个对象来为您进行编码:

var data = {a :"sadahdka sarr    &nbsp"};

jQuery.ajax({
    type: "POST",
    url: "function/postbai.php",
    data: data
}).done(function (html) {
    alert(html);
});

在将字符串发送到服务器之前对其进行转义,并用PHP对其进行解码

JS:

PHP:


嗨,桑吉。欢迎来到StackOverflow!如果你发现一个回答回答了你的问题,请选择它作为答案-你可以花尽可能多的时间来选择答案。请更清楚地问你的问题。不要在问题中写入标记。谢谢:()(()()()()()()()()()()()()
var data = {a :"sadahdka sarr    &nbsp"};

jQuery.ajax({
    type: "POST",
    url: "function/postbai.php",
    data: data
}).done(function (html) {
    alert(html);
});
data : "a="+escape(a);
urldecode($_POST['a']);