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

  • Home
  • SEARCH
  • 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 background info: of the three database tables that are relevant for this question,
As a quick explanation, I created an image that resizes to fill the background
Quick background: writing a module. One of my objects has methods that may or
Real quick background : We have a PDFMaker (HTMLDoc) that converts html into a
For a quick background, I have an app that I currently support which runs
Here's the quick background: I've got a client and a server program that are
Quick background I have a concurrent map I used to cache some values that
So the quick background is that I have a page listing a set of
Quick background: I'm programming in PHP, I have a domain model with a separate
Quick question. For some reason links referencing the home page contain an extra /web/guest/home

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.