Skip to content Skip to sidebar Skip to footer

How To Pass % In A Url Query String?

I am trying to pass a string via HTTP request which has one of the character as % in the URL query string. url = url + '?q=' + str + '&block=' + block; // str contains the '%

Solution 1:

You should url-encode all the values you are passing as query parameters, but the url-encoding for % is %25

Update: if you're constructing the query parameters in javascript, you probably want to do:

url=url+"?q="+encodeURIComponent(str)+"&block="+encodeURIComponent(block)

(Updated again with ZeissS' very helpful suggestion to use encodeURIComponent instead of escape. See also http://xkr.us/articles/javascript/encode-compare/)

Solution 2:

Pass your string trough the function encodeURI(...) it will escape all the special characters not only the %

Solution 3:

Solution 4:

URLEncodedFormat() in ColdFusion

Solution 5:

We can use URLEncodedFormat() in ColdFusion as well as we can use the below mentioned one.

  • encodeURI(...)
  • encodeURIComponent

This two also help us to resolve our issue.

Post a Comment for "How To Pass % In A Url Query String?"