2011-05-30 60 views

回答

0

你只包括它通常在查询字符串:http://test?myid=5&otherarg=3

2

尝试类似:

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

location.href = 'http://test.com/sometest.html?myid=5&someotherid=6'; 
0
var myid = 5; 
window.location = "http://test?myid=" + myid; 
0

如果你只是想调用它。而不要去它: 使用AJAX请求:

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

在这里,在jQuery的。但是互联网上有足够的非jQuery示例。

1

如果“做一个‘GET’打电话到URL”你的意思是改变当前位置到一定的网址,所有你需要做的就是分配新的URL到location变量:

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

如果你想加入一些查询参数构造URL,你可以这样做:

newUrl += "?myid=" + myid; 

此外,您可以使用函数的参数映射到网址:

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:此功能仅适用于在params对象INT /布尔/字符串变量。对象和数组不能用于这种形式。