jQuery - 我需要对变量进行 URL 编码吗?

发布于 2024-12-05 16:06:24 字数 1086 浏览 2 评论 0原文

我正在使用 ColdFusion 9 和最新最好的 jQuery。

在我的页面顶部,我使用这个:

<cfajaxproxy cfc="artists" jsclassname="jsApp">

我有一个搜索字段:

<input id="Artist" class="Search" type="text">

当用户在搜索字段中键入内容时,该值将传递到 jQuery 函数中:

$(".Search").keyup(function() {
  var Artist = $("#Artist").val();
  var QString = "Artist=" + Artist;
  $("#ArtistSearchResultsDiv").load("ArtistSearchResults.cfm?"+QString);
});

搜索结果 div 会在 CFSCRIPT 中加载包含这些项目的页面:

objArtists = createObject("component", "artists");
GetArtists = objArtists.getArtists(Artist);

我有运行查询并返回正确记录的 CFC。

问题是,当我在搜索框中键入内容时,一旦按下空格,就不会再向 QString 变量添加任何值,因此这些值不会传递给查询。

以下是搜索“The Beatles”时 Firebug 中搜索字符串的大小:

GET http://127.0.0.1:8500/WebSites/AwesomeAlbums/GlobalAdmin/ArtistSearchResults.cfm?Artist=The

一旦看到空格,它就会停止。

因此,如果您正在搜索“The Beatles”,则只有值“The”会被传递到 QString 变量中。如果您搜索“Celine Dion”,则只会搜索到“Celine”。

我假设我需要以某种方式对 QString 进行 URL 编码。这是正确的吗?我该怎么做?

I am using ColdFusion 9 and the latest and greatest jQuery.

At the top of my page, I use this:

<cfajaxproxy cfc="artists" jsclassname="jsApp">

I have a search field:

<input id="Artist" class="Search" type="text">

When a user types in the search field, the value is passed into a jQuery function:

$(".Search").keyup(function() {
  var Artist = $("#Artist").val();
  var QString = "Artist=" + Artist;
  $("#ArtistSearchResultsDiv").load("ArtistSearchResults.cfm?"+QString);
});

The search results div loads a page with these items in CFSCRIPT:

objArtists = createObject("component", "artists");
GetArtists = objArtists.getArtists(Artist);

I have a CFC that runs the query and returns the correct records.

The PROBLEM is that when I type in the search box, as soon as I hit a space, no further value is added to the QString variable, and so those values aren't passed to the query.

Here's how much search string looks in Firebug when searching for "The Beatles":

GET http://127.0.0.1:8500/WebSites/AwesomeAlbums/GlobalAdmin/ArtistSearchResults.cfm?Artist=The

It's stops as soon as it sees a space.

So, if you were searching for "The Beatles", only the value "The" would be passed into the QString variable. If you were searching for "Celine Dion", only "Celine" would be passed.

I am assuming that I need to URL encode the QString somehow. Is that correct? How do I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

眼藏柔 2024-12-12 16:06:24
var QString = "Artist=" + encodeURIComponent(Artist);
var QString = "Artist=" + encodeURIComponent(Artist);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文