Poll Results: Client-Side Request Object

The Latest Results

Total Number of Votes
214
Is this useful?
Yes 87%, No 13%
Do you need more documentation (if yes tell me what)?
Yes 24%, No 76%
Did it solve your programming problem?
Yes 83%, No 17%
Did you find this via a search engine?
Yes 84%, No 16%
Did you find any bugs (if yes tell me about them)?
Yes 12%, No 88%
Could the script be improved (if yes tell me how)?
Yes 29%, No 71%
Do you understand how to use it (if no tell me why)?
Yes 87%, No 13%
Rate this script: (0 = poor, 5 = very good)
[4.02 / 5]

Instant Feedback

Zirius

11th Jun 2004 14:36 GMT

your script is really cool!!!

Gregg

11th Jun 2004 16:01 GMT

Fantastic Script! Just what I needed! Thank you.

Kezia

16th Sep 2004 08:34 GMT

Thanks for giving me solution of my problem :) especially HTMLEncode script.

Hugh Abbott

26th Oct 2004 11:45 GMT

Genius - I love you!

Rob

29th Dec 2004 15:26 GMT

This Script works great! Thanks!

Renzo

15th Feb 2005 14:34 GMT

Solved my problem. Thanks very much. I think this for (var i=0; i<Request.QueryString.Count; ++i) needs correction: for (var i=1; i<Request.QueryString.Count; ++i) because for some obscure reason the Request.QueryString enumeration index starts with 1.

Andrew [ admin ]

15th Feb 2005 15:03 GMT

Re: Renzo
I think you're referring to the examples in the 'advanced' section, right? If so I think you're right - looks like a typo (which is fixed now - a documentation bug that's been there for 4 years!). The starting value is 1 rather than 0 as it's mimicking the behaviour of the Request.QueryString() collection in Classic ASP - so blame Microsoft :) Cheers.

Junior Programmer

21st Feb 2005 06:18 GMT

Obfuscating a freeware script is pointless. How did you learn about scripting ? ... do you not want others to learn from you ?. Oh I've just seen the "made in GB" bit at the end of the page ... that explains it !

Andrew [ admin ]

21st Feb 2005 09:49 GMT

Re: Junior Programmer
The script is not obfuscated for the sake of it. The script has its whitespace removed to make it faster to download for end-users - thus turning a 7.77KB script into a 5.27KB one. Every KB counts. If you wanted an expanded version all you had to do was ask. Since you chose to be offensive instead that option is no longer available to you.

Just2Click

9th Mar 2005 19:35 GMT

Hi Andrew, A great script, I didn't have time to look into it but it solved my problem. Is it possible to get an extended version? I'd like to take a look and learn a thing or to :-) Cheers again, you're really a handful

Andrew [ admin ]

10th Mar 2005 15:19 GMT

Re: Just2Click
Sure, although I'll need an email address to send it too.

"you're really a handful" - ??

Mgccl

20th Apr 2005 13:32 GMT

what does the script do?get a information from sever? i need to get some information in a server,it need me to login first, i can get some information by go on the site, but if i don't want to get on the site to see the change of the data(like how much money i got now),can i use this script for it?

Andrew [ admin ]

20th Apr 2005 14:04 GMT

Re: Mgccl
> what does the script do?
Implements ASP's Request.QueryString() command but using client-side javascript only.

> get a information from sever?
There is no server-side interaction here, it's just providing a Collection interface to the URI querystring.

> i need to get some information in a server
Sounds like you want to make a HTTP Request then using authentication, but that has nothing to do with this client-side Request Object script.

Troy

11th May 2005 17:20 GMT

A very elegant solution compared to the hackish javascript querystring functions I've used in the past. I haven't used the script enough to be in a position to offer improvements...but....would it be a better default to return null if the key does not exist rather than javascript's 'undefined'? This would prevent me having to use the Count property. For example, I have code where a date may be passed. I want to do this: if (Request.QueryString("dt" )) { do something; } If dt does not exist in the url, your object will return 'undefined' which makes the above prove true when I want/expect it to be false. So instead I'm doing: if ((Request.QueryString("dt").Count) && (Request.QueryString("dt" ))) { do something; } I'm trying to think when returning 'undefined' instead of null would be helpful, and I can't think of anything. I think returning null would be a better default. If I want to know if the key even exists, then I can use your Count property. Thanks for a great script! Enjoy the pint!

Andrew [ admin ]

11th May 2005 19:46 GMT

> would it be a better default to return null if the key does not exist rather than javascript's 'undefined'?
Hi Troy. I take the point. It used to return “undefined” as the javascript keyword of the same name rather than a string. As the keyword it used to meet the Boolean(false) requirement.

However, later on it came to my attention that certain Mac browsers (the older IE versions I think) were throwing exceptions as they hadn't implemented the keyword in their javascript engines. I worked around that problem by implementing “undefined” as a string, but yes a side-effect of that change is that it can cause a data type problem if the key is used without checking it beforehand.

Version 1.3 now returns the keyword null when de-referencing non-existent keys. Version 1.3 is available for download right now.

However, the Count() method is still the best means of defensively programming against unsafe data. It's also best used with the Item() method with a parameter argument of 1 to stop folks breaking your application by adding a duplicate key to the URL.

BTW: Thank-you very much for the virtual pint, that's really appreciated. A couple of other folks have bought a pint this year too, so for the first time I may actually break-even on hosting costs!

Chilidog

12th May 2005 21:07 GMT

Dude, you rock! I put this in my asp.net app and it runs like a champ.

Balts

24th May 2005 15:39 GMT

thankyou. it was exactly what i wanted and easy to understand, even for a beginner

Gayathri

26th May 2005 09:13 GMT

Give a detailed explaination of the concept....

Andrew [ admin ]

26th May 2005 11:06 GMT

Re: Gayathri
> Give a detailed explaination of the concept....
Sorry, you'll have to read up elsewhere on what querystrings are and why they are useful in web applications. Once you know why you might want to use them then there should be enough information in the documentation on this site to get you going. Think of this script as a pneumatic drill, if you don't know why you'd need one, then you probably don't need one!

Dev Gadre

25th Jul 2005 19:44 GMT

This script is quite useful and seems to be working fine. Thanks...!!

Murphy

18th Aug 2005 08:09 GMT

Thanks for it

Robert

12th Sep 2005 01:54 GMT

I really Like It!

BradleyT

30th Sep 2005 21:37 GMT

Just what I needed and works great - thanks!

Albear

16th Jan 2006 16:18 GMT

just want was required.. 2 years on and stil.l going well done

Jude

11th Feb 2006 21:07 GMT

This script sounds interesting, and if you believe this is the thing to do, then I will certainly take your word for it. Right now, I'm a little confused as to why this should be necessary. For query string parsing on the client-side, I'm in the habit of doing the "usual", and creating a simpler Javascript object - an Object filled with key|value pairs, where the values could be strings, arrays, or a mixture of these, depending on requirements. I have nearly completed my first ASP application. During the process, I found the structure of the Request collections made me feel like pulling my brain out through my nostrils with tweezers. To retain a measure of sanity, I use a function that inspects the required collection, then creates a native JScript object along the same lines as in the client-side scenario. This object is much easier for me to deal with in the rest of the script. While I'm suspicious that I may be missing something, and that my server-side approach may be fatally flawed, the thought of emulating the structure of the ASP Request.Querystring collection on the client -side strikes me, right now, as a form of masochism. er... :)

Metvacetz

21st Mar 2006 03:12 GMT

U did great! This is a real cool stuff. I could empower my ajax then.

Richard Bean

13th Apr 2006 06:23 GMT

About HTMLEncode(t) function, you need to declare variable "j" too, just put somewhere on the beginning of the function HTMLEncode a line: var j = 0; , because, if your javascript code already contains variable named "j", HTMLEncode function will change its value after "for" loop. But, in general, very useful stuff, thanks. :)

Kalp

22nd Feb 2007 13:38 GMT

great script! nice that it's I can access the url like in ASP, JSP an ASPX:) thanks.

Efi

25th Mar 2007 16:31 GMT

I found your script and it help me alot. I have a problem with my lang HEBREW and our charset is windows-1255 when I try to use the script this is what coming out: àôé Do you know what is the problem? Thanks

Andrew [ admin ]

25th Mar 2007 16:40 GMT

Re: Efi
There was a bug, well sort of a bug. It's fixed now so have another go and see if it works for you. Don't forget to download the latest version of the script (1.4 is the version you need, whereas you probably have version 1.3).

The detail: The native javascript method I was using for converting from URLEncoding back to plain text doesn't support Unicode very well. I've switched to using an alternative method. However, this alternative is not supported when using Internet Explorer 5.0 and below (or other browsers that don't support Javascript 1.5 — so they default to using the old method instead).

Mita

21st Jul 2008 10:25 GMT

when i m writing this code, I am getting error like Request is null or not an object.

Andrew [ admin ]

21st Jul 2008 16:58 GMT

Re: Mita
That one's explained in the documentation, see the 'Troubleshooting' section.

Adam

31st Jul 2008 00:03 GMT

This is the best example of how to do the HTMLEncode function I have found! I have searched for several days to find anything even this close.

However, I found two extremely *minor* issues: 1. The order in which the replacements are made using the regular expression version of the getHTMLEncode function need to be reversed. 2. You don't account for characters above 0X80 in either version of getHTMLEncode.

From Microsoft's MSDN web site on Server.HTMLEncode(): * The less-than character (<) is converted to &lt;. * The greater-than character (>) is converted to &gt;. * The ampersand character (&) is converted to &amp;. * The double-quote character (") is converted to &quot;. * Any ASCII code character whose code is greater-than or equal to 0x80 is converted to &#<number>, where <number> is the ASCII character value.

I am working on something for item #2 and will post those changes when completed.

Andrew [ admin ]

31st Aug 2008 09:48 GMT

Re: Adam
I disagree on point 1 — if the ampersand is replaced later then it will incorrectly encode the other ampersand replacements, the other replacements can take place in any order. However, I agree on point 2. The scripts are not intended to replicate fully the functionality of Server.HTMLEncode, only to stop marked-up content from executing.

Jeremy

24th Mar 2009 18:23 GMT

Please help others; I stumbled upon this through a link in a forum, Google did not put this high enough for me to find it. I was querying ‘javascript request.querystring'. This is Awesome, and works as stated; thank you for sharing with the rest of us!

Dileep Kumar

18th Jun 2009 09:44 GMT

This is very nice and useful. The same function can be used for decoding. To decode just reverse the replace character order. Eg.var arrE=[["&amp;","&"], ["&quot;","\""] ,["&lt;","<"], ["&gt;",">"]];

Anonymous Coward

4th Aug 2009 13:55 GMT

Good coding, thx, did the job.

Elder Soto

2nd Oct 2009 02:32 GMT

Muchas Gracias me ha ayudado mucho para capturar los valores desde pagina en ASP.NET

Anonymous Coward

19th Apr 2010 16:46 GMT

Too bad the Extended code is hard to read due to shortcuts, and failure to be lint free. Looks promising if it could be cleaned up a bit. try http://jslint.com to help with the clean up. and as it says it will hurt your feeling but it will make you a better coder.

David

19th May 2010 04:14 GMT

Hey thanks a lot for sharing such a nice and informative article,Really a very good content and helpful but Extended code is hard to read due to shortcuts, and failure to be lint free.

By the way for more information check this link <a href="http://www.eccouncil.org/cert ification/ec-council_certified_secu re_programmer.aspx"> http://www.eccouncil.org/certification/ec-council_certified_secure_programmer.aspx</a>

William

5th Jul 2010 14:05 GMT

Request is undefined!

Andrew [ admin ]

5th Jul 2010 14:11 GMT

Re: David
The script was written to be small, ergo, "shortcuts" as you put it. I'm not a fan of "lint", there's code good and then there's being anal for being anal's sake.

Andrew [ admin ]

5th Jul 2010 14:12 GMT

Re: William
User fail. This error has it's own section in the documentation.

Feedback Form



Note: Content is not automatically censored, but if you post a message your IP address / addresses will be recorded.