2011-10-09 42 views
0

我如何通過一個變量在xmlhttp.send功能我如何通過一個變量在xmlhttp.send功能

var str = "hello" 
xmlhttp.open("POST","./omnama.php",true); 
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
xmlhttp.send("fname=+str"); ' it fills the database with str but not with hello 

我嘗試這些不工作

xmlhttp.send("fname=" +str,"lname=" +cool); 

它填補了FNAME有變量值但不是lname,lname給出一個空字符串如果我有很多變量要傳遞,我該如何組合?

+0

xmlhttp.send(其中 「fname =」 + STR); – kukipei

+0

@kukipei它的工作崗位它作爲答案我會接受! – niko

回答

2
xmlhttp.send("fname=" + str); it should work 

xmlhttp.send("fname=" +str + "&lname=" +cool); 
+0

我試過這些方法不工作,請幫助這些xmlhttp.send(「fname =」+ str,「lname =」+ cool); – niko

+0

我剛編輯答案 – kukipei

+0

哇它的工作,但天哪語法太難以理解,你可以解釋與評論請! – niko

2

這只是一個字符串。像其他任何字符串一樣對待它。

foo("some string" + another_string_stored_in_a_variable); 
相關問題