Mootools 请求对象不允许我拥有 '+'在我的查询字符串中签名
我有以下 Javascript/Mootools 代码:
var str = self.tI.get('value').replace(/\s/g,'+'),
data = 'action=getplaces&str=' + str + '&latLng=' + $('coords').get('value'),
r = new Request({
url: 'action.php',
method: 'get',
link: 'cancel',
onSuccess: function (response) {
/* Do Stuff */
}
}).send(data);
console.log(str);
在第一行,我用 + 号替换所有空格。当我在控制台中记录 str 的值时,我得到了适当的值(即:“blabla+bla”)
但是,当我发送请求时,我的请求失败。如果我查看标题和查询字符串,+ 号会再次被空格替换(即:“blabla bla”),
这是怎么回事?有办法解决吗?
I have the following Javascript/Mootools code:
var str = self.tI.get('value').replace(/\s/g,'+'),
data = 'action=getplaces&str=' + str + '&latLng=' + $('coords').get('value'),
r = new Request({
url: 'action.php',
method: 'get',
link: 'cancel',
onSuccess: function (response) {
/* Do Stuff */
}
}).send(data);
console.log(str);
On the first line I replace any spaces with + signs. When I log the value of str in the console, I get the appropriate value (ie: 'blabla+bla')
However, when I send the request, my request fails. If I look at the headers and the query string, the + sign is simply replaced again with a space (ie: 'blabla bla')
What's up with that? And is there a way around it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于任何想知道的人来说,我的问题最终出在服务器端。一旦数据到达服务器端,我试图将其合并到另一个 URL 中,但服务器已经将 %20 和 + 解析为空格。因此必须在服务器端进行一些字符串操作。
For anybody wondering, my problem ended up being server side. Once the data got to the server side, I was trying to incorporate it in another URL but the server had already parsed the %20 and the +'s to spaces. So had to do some string manipulation on the server side.
您需要转义加号,因为它是 HTML Url 中的保留字符
将其替换为
+
You need to escape plus as it's a reserved character in HTML Url's
replace it with
+