Jump to content

querystring parsing


fooDigi

Recommended Posts

i can parse a well formatted querystring just fine, the problem arises when a second '?' gets put towards the end, and i can not retrieve the variables after that. how would i do this.

 

the problem should be fixed at the source, by removing the second '?'. but i must be prepared for poorly formatted urls.

 

here is the function i use.

 

function getQueryString(q){
var fullS = window.location.search.substring(1);
if(fullS.indexOf(q) != -1){
	var varA = fullS.split('&');		
	for(i=0; i<=varA.length; i++){
		nameA = varA[i].split('=');	
		if(nameA[0] == q){
			retVal = nameA[1];
			break;
		}
	}
	if(retVal.length > 0)
		return retVal;
	else
		return false;
}else{
	return false;
}
}
document.write(getQueryString('qs'));

 

thx for any help

foo

Link to comment
Share on other sites

i can parse a well formatted querystring just fine, the problem arises when a second '?' gets put towards the end, and i can not retrieve the variables after that. how would i do this.

 

the problem should be fixed at the source, by removing the second '?'. but i must be prepared for poorly formatted urls.

 

If all you want to do is remove the second ?, use a regular expression before any other processing of the search string.

 

here is the function i use.

 

function getQueryString(q){
var fullS = window.location.search.substring(1);

 

try:

 

var fullS = window.location.search.substring(1).replace(/\?/g,'');

 

 

but be careful: that will replace all instances of "?" in the query string.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.