[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

URL.Encode/Decxode Generating Error

Posted on 2014-03-06
4
Medium Priority
?
250 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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 the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

656 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