?
Solved

URL.Encode/Decxode Generating Error

Posted on 2014-03-06
4
Medium Priority
?
246 Views
Last Modified: 2014-03-21
Hello,

I am using this piece of code to encode and decode a URL:

<script language="javascript" runat="server">
URLDC = {
    encode : function(s){return encodeURIComponent(s).replace(/'/g,"%27").replace(/"/g,"%22")},
    decode : function(s){return decodeURIComponent(s.replace(/\+/g, " "))}
}
</script>

Open in new window


Encoding seems to work fine, however decoding doesn't, and generates this error:

Microsoft JScript runtime  error '800a01b6'

Object doesn't support this property or method

/deps/top-regions-data.asp, line 116

Assistance appreciated!

Thank you
0
Comment
Question by:Nico2011
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
Tony O'Byrne earned 2000 total points
ID: 39910396
Did you try encodeURI / decodeURI?  (rather than encodeURIComponent)

Seems to be available in all major browsers:
http://www.w3schools.com/jsref/jsref_decodeURI.asp

I realize Component is for components of the URI, but perhaps encode/decodeURI will meet your needs?

Something else to check...
perhaps it's not the decodeURIComponent that's the real problem...  Maybe it's the s.replace(...).  Maybe - just maybe - 's' is undefined (or something else - like an empty object {}) at that point; undefined (or an empty object) doesn't have a .replace function.  Maybe try (s || "").replace(...).  While "||" is logical OR, it is also the JS null coalescing operator.
0
 

Author Closing Comment

by:Nico2011
ID: 39945252
I am very sorry I did not respond before - I only found out that you had posted an answer when I requested assistance - the answer didn't show before!
0
 
LVL 6

Expert Comment

by:Tony O'Byrne
ID: 39945294
Not to worry.  Glad I could help. :)
0
 

Author Comment

by:Nico2011
ID: 39945330
Thanks & have a good weekend :-)
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question