Solved

URL.Encode/Decxode Generating Error

Posted on 2014-03-06
4
226 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
Comment Utility
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
Comment Utility
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
Comment Utility
Not to worry.  Glad I could help. :)
0
 

Author Comment

by:Nico2011
Comment Utility
Thanks & have a good weekend :-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

743 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

18 Experts available now in Live!

Get 1:1 Help Now