2011-05-30 146 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 /布爾/字符串變量。對象和數組不能用於這種形式。