Solved

URL.Encode/Decxode Generating Error

Posted on 2014-03-06
4
238 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
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…

726 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