Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove last params from url

How to remove last params from the url for instance, i have url such as

http://localhost/autoservice/public_html/tickets/load_service/6

i want to get this result

http://localhost/autoservice/public_html/tickets

how to make this with jquery or javascript

i have tried many solutions by reading many post on stack but i can't get it right

 var url       = $(location).attr('href');
like image 822
Share Knowledge Avatar asked Dec 08 '22 04:12

Share Knowledge


1 Answers

Try this simple method using lastIndexOf() and slice()

url = 'http://localhost/autoservice/public_html/tickets/load_service/6';
url = url.slice(0, url.lastIndexOf('/'));
url = url.slice(0, url.lastIndexOf('/'));
alert(url);
like image 60
Pranav C Balan Avatar answered Dec 18 '22 19:12

Pranav C Balan