jQuery - 我需要对变量进行 URL 编码吗?
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)