2012-03-09 23 views

回答

0

對於HTML:

"sample1.php?q=" + str + "&otherParam=" + other; 

對於XHTML/XML:

"sample1.php?q=" + str + "%26otherParam=" + other; 
+0

why'& otherparm' – mplungjan 2012-03-09 12:55:05

+0

「&」用於顯示HTML文本中的&符號,而不是JS – jondinham 2012-03-09 13:03:08

+0

@mplungjan否,那是不正確的。&是「&」的HTML編碼實體。正確的URI編碼是%26。將「&」傳遞到一個URI創建參數名「放大器; otherParam」如果不通過HTML解碼後的第一 – austincheney 2012-03-09 17:39:25

0

定義「多個值」。如果你的意思是多個變量,你可以這樣做:

$url = "sample1.php?q=".$str."&second=".$str2; 
0

試試這個代碼:

<script> 
function make_full_url(Page_URL,Params) { 
    Page_URL += "?"; 
    for Key in Params 
    Page_URL += Key+"="+Params[Key]+"&"; 
    return Page_URL; 
} 

//test 
Page_URL = "sample1.php"; 
Params = new Array(); 
Params["q"] = Str; 
Params["something"] = "something"; 

Full_URL = make_full_url(Page_URL,Params); 
</script> 
+0

我只是想發送三個變量,所以它是這樣的? 'sample1.php?q ='+ str'&a ='+ a'&b ='+ b' – user1122910 2012-03-09 12:52:36

+0

URL =「sample1.php?q =」+ str +「&a =」+ a +「&b="+b; – jondinham 2012-03-09 12:55:36

0

我希望我明白你的正確...做一個數組你的值和循環的關鍵值來concat你的url字符串

$values = array('q' => $str, 'val2' => $val2); 
$url = 'sample1.php'; 
$pos = 0; 
foreach($values as $key => $value) { 
    $url .= ($pos>0 ? '&' : '?').$key.'='.urlencode($value); 
    $pos++; 
}