我如何在xmlhttp.send函数中传递变量

时间:2011-10-09 08:40:14

标签: ajax

如何在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给出一个空字符串如果我要传递很多变量,我该如何组合?

2 个答案:

答案 0 :(得分:2)

这只是一个字符串。像任何其他字符串一样对待它。

foo("some string" + another_string_stored_in_a_variable);

答案 1 :(得分:2)

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

xmlhttp.send("fname=" +str + "&lname=" +cool);
相关问题