Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery remove one URL variable

I am busy making a web application, which needs to process a lot of erorrs and stuff so i made a jquery ui dialog box. Which shows these errors. The errors are retrieved by database. for example:

when my username/password is incorrect when i try to log in i get redirected to

http://domain.com/?do=login&e=login-incorrect

the application then know he has to search for the login-incorrect error in the database and show that to the user. Now this all goes very well. Except that when for some reason the user would reload this particular page he wel get the error message again while he doesnt need to get it.

so my plan is to bind some kind of function to the close event of the dialog box and redirect the user to the same page bug without the e parameter in the URL. How could i achieve this. I tried all sorts of stuff. But could not get it to work.

What i tried:

bassicly tried getting all possible parameters and stitching those together except for the e parameter. like so:

$ERROR = $_GET['e'];
$DO = $_GET['do'];
$P = $_GET['p'];
$C = $_GET['c'];
$T = $_GET['t'];
$ACTION = $_GET['action'];

// URL WITHOUT ERRORS
$needP = "";
$needACTION = "";
$needDO = "";
if($P != ""){
    $needP = "p=".$P."&";
}
if($DO != ""){
    $needDO = "do=".$DO."&";
}
if($ACTION != ""){
    $needACTION = "action=".$ACTION."";
}
$NOERRORURL = $BASEURL."?".$needP.$needDO.$needACTION;

But it does not work and its ugly

like image 562
sn0ep Avatar asked Aug 19 '11 19:08

sn0ep


People also ask

How to remove parameter from url?

Just pass in the param you want to remove from the URL and the original URL value, and the function will strip it out for you. To use it, simply do something like this: var originalURL = "http://yourewebsite.com?id=10&color_id=1"; var alteredURL = removeParam("color_id", originalURL);

How to remove query params from url JS?

To remove a querystring from a url, use the split() method to split the string on a question mark and access the array element at index 0 , e.g. url. split('? ')[0] . The split method will return an array containing 2 substrings, where the first element is the url before the querystring.


1 Answers

location.href=location.href.replace(/&?e=([^&]$|[^&]*)/i, "");

This will remove all instances of the e parameter from the query string and refresh the page.

like image 197
jli Avatar answered Sep 22 '22 16:09

jli