JQUERY AJAX,发送到服务器的空格问题,为什么?

发布于 2024-08-25 11:18:08 字数 355 浏览 3 评论 0原文

我使用以下代码将其发送到服务器,然后将其发送到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夕嗳→ 2024-09-01 11:18:08

/search/spotlight/?q=FirstName%20LastName 是有效的网址字符串。我的猜测是您的服务器端脚本需要更好地处理事情。

顺便说一句,您不需要自己构建查询字符串,jquery 可以为您做到这一点:

$.ajax({
url: '/search/spotlight/',
data: {"q": $(this).val()},
success: function(data) {
}
});

/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:

$.ajax({
url: '/search/spotlight/',
data: {"q": $(this).val()},
success: function(data) {
}
});
荒芜了季节 2024-09-01 11:18:08

在客户端看起来没问题。只需使用

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).

-黛色若梦 2024-09-01 11:18:08

是的... %20 表示空格

,但你应该像这样设置数据

data: {'q': $(this).val()}

it is right ... %20 means space

but you should set the data like this

data: {'q': $(this).val()}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文