[英]How to escape + in post call content type as application/x-www-form-urlencoded
I have a ajax call with content type: xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 我有一个内容类型为ajax的调用:xhr.setRequestHeader('Content-Type','application / x-www-form-urlencoded');
Now I have a data like: "firstName=bob+builder"; 现在,我有一个数据,例如:“ firstName = bob + builder”;
When the data is sent to the server the browser replaces the + sign with space and the data goes as firstName: bob builder 当数据发送到服务器时,浏览器用空格替换+号,并且数据以firstName的形式出现:bob builder
Is there a way to escape that + sign? 有没有办法逃避那个+号? as far as I know there is no way except that it should be handled on the server side, replacing space with + sign. 据我所知,除了应该在服务器端处理之外,没有其他方法,用+号代替空间。 Am I wrong? 我错了吗?
You should be able to encode on the client side. 您应该能够在客户端进行编码。 With Javascript: 使用Javascript:
encodeURIComponent("bob+builder"); //bob%2Bbuilder
The server side code should then simply decode. 然后,服务器端代码应简单地解码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.