I need an advice regarding URL parameters. Sometimes when I click a button which switches the page from page 1 to page 2, it removes some GET parameters values.
Here is an example for an <a>
tag:
<a href="/forms/page_name/dashboard.php?page=page1&pg=<?=$_GET['pg']?>&type=fa&emp=<?=$_GET['emp']"> Name of Link </a>
when I click that link, &pg
and other parameters are now empty except the dashboard.php
. So I manually code it through javascript just to do it easier like this:
$('.leave_info').each(function(index, element){
$(element).dblclick(function(e){
let pg = $(this).val()
let page = $(this).data('page')
let type = $(this).data('type')
let emp = $(this).data('emp')
let super_id = $(this).data('id')
window.location.href ="/forms/leaver/dashboard.php?page=page1&type="+type+"&pg="+pg+"&emp="+emp
})
})
Thanks for the help…
2
Answers
If you are asking how to construct a new URL keeping (most of) the GET parameters in a better way, you can use
URL
andURLSearchParams
objects.(Obviously, the stack snippet won’t originally have any GET arguments, so you can’t see how they are preserved by running it in here.)
If you just want to redirect to the same page by modifying some of the params, this is even easier (don’t actually run this here, as it will try to redirect the snippet):
It works fine but I think it was the SERVER issue, have you asked your network admin for some rules in the network? Can you check .htaccess ?