How to go to URL with parameters

How can I do the following in javascript?

Make a call GETfor the URL with the optional .eg option

I want to do GETin http: // test with parameter myid = 5.

Thanks Boots

+3
source share
5 answers

try something like:

location.replace('http://test.com/sometest.html?myid=5&someotherid=6');

or

location.href = 'http://test.com/sometest.html?myid=5&someotherid=6';
+2
source

If you want to change the current location to a specific URL using the “Do a” GET command on the URL, all you need to do is assign a new URL to the variable location:

var newUrl = "http://test";
window.location = newUrl;

If you want to build a url by adding some query parameters, you can do:

newUrl += "?myid=" + myid;

Alternatively, you can use the function to map parameters to URLs:

function generateUrl(url, params) {
    var i = 0, key;
    for (key in params) {
        if (i === 0) {
            url += "?";
        } else {
            url += "&";
        }
        url += key;
        url += '=';
        url += params[key];
        i++;
    }
    return url;
}

:

window.location = generateUrl("http://test",{ 
    myid: 1,
    otherParameter: "other param value"
});  

obs: int/bool/string params. .

+1

: http://test?myid=5&otherarg=3

0
source
var myid = 5;
window.location = "http://test?myid=" + myid;
0
source

If you only want to call. And don't go to it : Use an AJAX request:

$.ajax({
    url: 'http://test/?myid=5'
});

Here in jQuery. But on the Internet there are enough examples other than jQuery.

0
source

All Articles