简体   繁体   中英

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

In my code i have to send an ajax POST call like this:

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

the problem is that if, for example, the variable psid contain some & char, like "test.php?P1=12&P2=232&P3=123" the call pass just part "test.php?P1=12", truncate at the first &. I have to use this method and not jQuery $.post but i can't figure out how is possible pass variable with & char within.

Thanks in advance

AM

& is the character used to separate key/value pairs in form encoded data (including in query strings).

You have to escape it as %26 if you want to send it as data.

encodeURIComponent() will do that for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM