Solved

URL.Encode/Decxode Generating Error

Posted on 2014-03-06
4
232 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
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
Tony O'Byrne earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now