Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1063881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:51:02+00:00 2026-05-16T18:51:02+00:00

When encoding a query string to be sent to a web server – when

  • 0

When encoding a query string to be sent to a web server – when do you use escape() and when do you use encodeURI() or encodeURIComponent():

Use escape:

escape("% +&=");

OR

use encodeURI() / encodeURIComponent()

encodeURI("http://www.google.com?var1=value1&var2=value2");

encodeURIComponent("var1=value1&var2=value2");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:51:02+00:00Added an answer on May 16, 2026 at 6:51 pm

    escape()

    Don’t use it!
    escape() is defined in section B.2.1.1 escape and the introduction text of Annex B says:

    … All of the language features and behaviours specified in this annex have one or more undesirable characteristics and in the absence of legacy usage would be removed from this specification. …
    … Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code….

    Behaviour:

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape

    Special characters are encoded with the exception of: @*_+-./

    The hexadecimal form for characters, whose code unit value is 0xFF or less, is a two-digit escape sequence: %xx.

    For characters with a greater code unit, the four-digit format %uxxxx is used. This is not allowed within a query string (as defined in RFC3986):

    query       = *( pchar / "/" / "?" )
    pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"
    unreserved    = ALPHA / DIGIT / "-" / "." / "_" / "~"
    pct-encoded   = "%" HEXDIG HEXDIG
    sub-delims    = "!" / "$" / "&" / "'" / "(" / ")"
                  / "*" / "+" / "," / ";" / "="
    

    A percent sign is only allowed if it is directly followed by two hexdigits, percent followed by u is not allowed.

    encodeURI()

    Use encodeURI when you want a working URL. Make this call:

    encodeURI("http://www.example.org/a file with spaces.html")
    

    to get:

    http://www.example.org/a%20file%20with%20spaces.html
    

    Don’t call encodeURIComponent since it would destroy the URL and return

    http%3A%2F%2Fwww.example.org%2Fa%20file%20with%20spaces.html
    

    Note that encodeURI, like encodeURIComponent, does not escape the ‘ character.

    encodeURIComponent()

    Use encodeURIComponent when you want to encode the value of a URL parameter.

    var p1 = encodeURIComponent("http://example.org/?a=12&b=55")
    

    Then you may create the URL you need:

    var url = "http://example.net/?param1=" + p1 + "&param2=99";
    

    And you will get this complete URL:

    http://example.net/?param1=http%3A%2F%2Fexample.org%2F%Ffa%3D12%26b%3D55&param2=99

    Note that encodeURIComponent does not escape the ' character. A common bug is to use it to create html attributes such as href='MyUrl', which could suffer an injection bug. If you are constructing html from strings, either use " instead of ' for attribute quotes, or add an extra layer of encoding (' can be encoded as %27).

    For more information on this type of encoding you can check: http://en.wikipedia.org/wiki/Percent-encoding

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if encoding using escape(data) in javascript, how to decode it in server side? I
Is there Apache utility that takes Query String and some encoding and return Map
I need to extract Chinese characters from the query string in an ASP.NET web
I want to pass a query string with an object to my REST server,
I've been having some character encoding problems with twitter's text query string parameter. a)
Related to this question: "Fix" String encoding in Java My project encoding is UTF-8.
Post data isn't sent as a query string, so would there be any advantage
What encoding we need to use to save a file as text file(of type
I have an mp3 encoding server running on Ubuntu (natty). This has been working
I have a query string I need to encrypt using AES in CBC mode

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.