开发者

jQuery - Do I need to URL encode a variable?

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 开发者_如何学Cdiv 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?


var QString = "Artist=" + encodeURIComponent(Artist);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜