JQUERY AJAX,发送到服务器的空格问题,为什么?
我使用以下代码将其发送到服务器,然后将其发送到 MYSQL 查询以通过搜索查找匹配项。
$.ajax({
url: '/search/spotlight/',
data: "q=" + $(this).val(),
success: function(data) {
}
});
当 Q 的 val 中有空格时,就会产生问题。我想知道我是否正确处理这个问题?我需要在 AJAX 调用中对值进行编码吗?或者这是我的后端的问题,即 ColdFusion
现在 JQUERY 正在将以下内容发布到服务器: /search/spotlight/?q=FirstName%20LastName
这是对的吗?
I'm using the following code to post to the server which is then sent to a MYSQL query to find matches via search.
$.ajax({
url: '/search/spotlight/',
data: "q=" + $(this).val(),
success: function(data) {
}
});
When Q's val has spaces in it, it's creating problems. I'm wondering if I'm handling this correctly? Do I need to encode the value in the AJAX call? Or is this a problem on my backend, which is ColdFusion
Right now JQUERY is posting the following to the server:
/search/spotlight/?q=FirstName%20LastName
is this right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
/search/spotlight/?q=FirstName%20LastName
是有效的网址字符串。我的猜测是您的服务器端脚本需要更好地处理事情。顺便说一句,您不需要自己构建查询字符串,jquery 可以为您做到这一点:
/search/spotlight/?q=FirstName%20LastName
is a valid url string. My guess is your server side script needs to handle things better.BTW you don't need to build the query string yourself jquery can do it for you:
在客户端看起来没问题。只需使用
Looks ok on the client side. Just use URLDecode on the string in ColdFusion, to turn %20 to space (and other special characters as well).
是的... %20 表示空格
,但你应该像这样设置数据
it is right ... %20 means space
but you should set the data like this