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 6174739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:48:08+00:00 2026-05-23T23:48:08+00:00

Quick background – I am making a jQuery ajax call to a service I

  • 0

Quick background –

I am making a jQuery ajax call to a service I wrote that returns a JSON response. The service accepts a web site URL (i.e. http://www.google.com, http://www.xyz.com/abc123). The format of the request is as follows:

http://www.mysite.com/[url]

… where [url] is a user provided URL (again, something like http://www.google.com/abc)

I need to URL encode the parameter, as mysite.com/www.google.com is giving me errors.

My problem is, all of the standard javascript encoding functionality does not actually encode the URL.

An example:

<html>
<head>
<script>
document.write("encodeURIComponent = " + encodeURIComponent("www.google.com") + "<br />");
document.write("encodeURI = " + encodeURI("www.google.com") + "<br />");
document.write("escape = " + escape("www.google.com"));
</script>
</head>
<body>
</body>

… has the following output:

encodeURIComponent = www.google.com
encodeURI = www.google.com
escape = www.google.com

What is the proper way to achieve this using JavaScript/jQuery?

I don’t think it’s relevant, but just in case, this is a Rails 3.0.7 app.

EDIT FOR MORE DETAIL

If http://www.google.com is already URL encoded, and periods are fine in my URL (www.mysite.com/www.google.com), why am I getting this error?

From Chrome Dev Tools:

GET http://localhost:3000/s/www.google.com 404 (Not Found)

My jQuery snippet:

$.getJSON("http://localhost:3000/s/" + encodeURI($("#txtURL").val()), function(data) {
        alert(data.result.url);
    });
  • 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-23T23:48:08+00:00Added an answer on May 23, 2026 at 11:48 pm

    This is a perfectly valid URL:

    http://mysite.com/s/www.google.com
    

    I suspect that you’re just running into the Rails format stuff (i.e. .html at the end of the URL sets the format to HTML, .js for JSON, …) so you just need to fix your route to keep the format auto-detection from getting in the way:

    map.connect '/s/:url', :requirements => { :url => /.*/ }, ...
    

    or

    match '/s/:url' => 'pancakes#house', :constraints => { :url => /.*/ }, ...
    

    or whatever routing syntax you’re using.

    If you don’t tell rails that the :url should match /.*/ (i.e. anything at all), it will try to interpret the periods in the route as format specifiers, that will fail and Rails will 404 because it can’t figure out how to route the URL.

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

Sidebar

Related Questions

Quick question. What do you think, I have a few sites that use a
Quick question. There is a legacy website (that is not under my control and
Quick background: when a key is pressed in a browser, three events are generated:
Quick background. I'm using the following: Windows XP Visual Studio 6.0 When you specify
The final code that worked for me was: <canvas id=bg-admin-canvas width=500 height=500 style=margin:15px; background:#09F;></canvas>
Quick add on requirement in our project. A field in our DB to hold
Quick question: Would it be a good or a bad idea to implement my
Quick question: what is the compiler flag to allow g++ to spawn multiple instances
Quick one, but thought I'd ask. Is there a better way of getting the
Quick design question. ClassA has a method called DoSomething(args) In DoSomething(), before it can

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.