Ajax POST XMLHttpRequest() 无法发送参数 with & characther

Ajax POST XMLHttpRequest() can't send parameters with & characther

本文关键字:with 参数 amp characther XMLHttpRequest POST Ajax      更新时间:2023-09-26

在我的代码中,我必须发送一个像这样的ajax POST调用:

var http = new XMLHttpRequest();
var url = "get_data.php";
var params = "bac="+pa+"&seid="+psid+"&wh="+height;
http.open("POST", url, true);

问题是,例如,如果变量PSID包含一些和字符,如"test.php?P1=12&P2=232&P3=123"呼叫通过只是部分"测试.php?P1=12",在第一个 &.我必须使用这种方法而不是jQuery $.post,但我无法弄清楚如何通过其中的char传递变量。

提前致谢

&是用于分隔表单编码数据(包括查询字符串)中的键/值对的字符。

如果要

将其作为数据发送,则必须将其作为%26转义。

encodeURIComponent()会为你做到这一点。