gpt4 book ai didi

javascript - & php 接收到的 json 的字符中断

转载 作者:行者123 更新时间:2023-12-03 12:12:41 25 4
gpt4 key购买 nike

我有一个包含更多对象的数组。如果一个对象包含 & 字符,则 & 后面的每个对象都不会被 php 接收。可能是什么问题?

这就是 AJAX

xmlhttp.open("POST", "get.php");
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send('data='+JSON.stringify(x));

这就是 PHP

$json = $_POST['data'];
echo $json;

输入时

a&b

我得到了

[[{"x":x,"y":"x","z":"z"}],[{"w":a

最佳答案

您还必须使用 encodeURIComponent 函数:

xmlhttp.send('data=' + encodeURIComponent(JSON.stringify(x)));

关于javascript - & php 接收到的 json 的字符中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24885957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com