1

I'm writing a piece of Javascript that takes in the title of the current page, and sends it to a form in a Rails 3 app. If the title is something like

Review - “Episode 20”

then when I pass that title to my form:

http://localhost:3000/notes/myform?title=Review - “Episode 20”

the title appears in my form as

Review - �Episode 20�

How do I fix this?

2 Answers 2

2

You can use encodeURI

console.log(encodeURI('Review - “Episode 20”')); 
// "Review%20-%20%E2%80%9CEpisode%2020%E2%80%9D"

I'm no Ruby pro, but I believe the Ruby way to decode this is CGI::unescape()

Sign up to request clarification or add additional context in comments.

Comments

0

Or use URI_escape:

enc_uri = URI.escape("http://example.com/?a=\11\15")
# => "http://example.com/?a=%09%0D"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.