How to pass GET request to window.location in JavaScript?
You need to first create a string with the required location in it:
<script>
window.location = 'www.site.com/members/?username=' + username_variable;
</script>
Or your way of doing it (using ES6 formatting):
<script>
window.location = 'www.site.com/members/?username={$member.username}';
</script>
Pass data without the use of window.location
The answer is yes. And the way to do it is to use a FORM. In particular, you should learn about the FORM method (learn about [REST][1] commands).
It sounds like you should be using POST.
[1]: https://www.restapitutorial.com/lessons/httpmethods.html#:~:text=The%20primary%20or%20most%2Dcommonly,or%20CRUD)%20operations%2C%20respectively.
How can I pass a query string to window.location.replace()?
Your list
variable only contains the value of the query '?list=123'
which for example would be '123'
You aren't creating a new query string....just adding that same value to end of the new url so it would look like "management.html123'
If you want the whole query string from current page passed to new page you can use location.search
location.replace("management.html" + location.search);
Or for just the 'list'
do:
location.replace("management.html?list=" + list);
window.location.href with POST instead of GET (or equivalent effect)
The way I have always done this (with jquery) is this.
var $form=$(document.createElement('form')).css({display:'none'}).attr("method","POST").attr("action","URLHERE");
var $input=$(document.createElement('input')).attr('name','FIRST NAME HERE').val("FIRST VALUE HERE");
var $input2=$(document.createElemet('input')).attr('name','SECOND NAME HERE').val("SECOND VALUE HERE");
$form.append($input).append($input2);
$("body").append($form);
$form.submit();
Adding multiple GET Parameters to URL using window.location.assign from checkboxes
First, do not use the same id
on multiple elements.
See Why is it a bad thing to have multiple HTML elements with the same id attribute?
Your problem is with this line
window.location.assign('?rooms=' + vals);
You need to dynamically update the query string.
Using this method
function updateQueryStringParameter(uri, key, value) {
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
}
else {
return uri + separator + key + "=" + value;
}
}
from add or update query string parameter
and custom attributes like
<ul data-type="rooms">
you can do
window.location.href = updateQueryStringParameter(window.location.href, $ul.attr('data-type'), vals);
instead of
window.location.assign('?rooms=' + vals);
How can I pass a Javascript ID value into window.location.href
in showPosition()
function you already have lat and long passed as position
and you can use it directly like this
function showPosition(position) {
geo_latitude.innerHTML = position.coords.latitude;
geo_longitude.innerHTML = position.coords.longitude;
window.location.href = "https://my_website/index.php?category=fast%20food&gps_geo_latitude=" + position.coords.latitude + "&gps_geo_longitude=" + position.coords.longitude;
}
Or, you can get them from DOM the same way you set them in your span
function showPosition(position) {
geo_latitude.innerHTML = position.coords.latitude;
geo_longitude.innerHTML = position.coords.longitude;
window.location.href = "https://my_website/index.php?category=fast%20food&gps_geo_latitude=" + geo_latitude.innerHTML + "&gps_geo_longitude=" + geo_longitude.innerHTML;
}
Passing parameter through "window.location.href"
Just add it in as a query string in the javascript
echo ("<script language='JavaScript'>
window.location.href='question.php?q_id=$q_id';
window.alert('Thank You! Your answer is online now.')
</script>");
Window location to another page with parameters
You are not using the parameter
string correctly in the ScriptManager.
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Replied!Thank you.');window.location ='eforum_main.aspx?forum_id=" + parameter + "';", true);
Related Topics
Regex to Remove Certain Characters At the Beginning and End of a String
Trouble Converting Dates String to Yyyy-Mm-Ddthh:Mm:Ss-Hh:Mm Format
Moment Js Get First and Last Day of Current Month
How to Save Binary Buffer to Png File in Nodejs
How to Close Toggle Menu When Clicking Navigation Item Anchor Link
Clear an Input Field With Reactjs
Regex With Space and Letters Only
How to Convert File to Base64 in JavaScript
How to Append Value to an Array Only If Not Exists and Remove It If Not
How to Pass Id from Modal in Boostrap to PHP File
How to Use If Statement Inside Json
How to Prevent Form to Reload Page After Onsubmit
Html Input File Selection Event Not Firing Upon Selecting the Same File