2011-10-09 41 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); 
相关问题