Poll Results: Client-Side Request Object
The Latest Results
Instant Feedback
Zirius
your script is really cool!!!
Gregg
Fantastic Script! Just what I needed! Thank you.
Kezia
Thanks for giving me solution of my problem :) especially HTMLEncode script.
Hugh Abbott
Genius - I love you!
Rob
This Script works great! Thanks!
Renzo
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 ]
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
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 ]
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
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 ]
Re: Just2Click
Sure, although I'll need an email address to send it too.
"you're really a handful" - ??
Mgccl
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 ]
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
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 ]
> 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
Dude, you rock! I put this in my asp.net app and it runs like a champ.
Balts
thankyou. it was exactly what i wanted and easy to understand, even for a beginner
Gayathri
Give a detailed explaination of the concept....
Andrew [ admin ]
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
This script is quite useful and seems to be working fine. Thanks...!!
Murphy
Thanks for it
Robert
I really Like It!
BradleyT
Just what I needed and works great - thanks!
Albear
just want was required.. 2 years on and stil.l going well done
Jude
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
U did great! This is a real cool stuff. I could empower my ajax then.
Richard Bean
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
great script! nice that it's I can access the url like in ASP, JSP an ASPX:) thanks.
Efi
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 ]
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
when i m writing this code, I am getting error like Request is null or not an object.
Andrew [ admin ]
Re: Mita
That one's explained in the documentation, see the 'Troubleshooting' section.
Adam
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 <. * The greater-than character (>) is converted to >. * The ampersand character (&) is converted to &. * The double-quote character (") is converted to ". * 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 ]
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
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
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=[["&","&"], [""","\""] ,["<","<"], [">",">"]];
Anonymous Coward
Good coding, thx, did the job.
Elder Soto
Muchas Gracias me ha ayudado mucho para capturar los valores desde pagina en ASP.NET
Anonymous Coward
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
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
Request is undefined!
Andrew [ admin ]
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 ]
Re: William
User fail. This error has it's own section in the documentation.