我有这个JavaScript代码,它将输入栏中输入的值发送到一个php文件,该文件根据输入字段中输入内容的值从数据库中提取行。我需要编辑此代码,以便JavaScript不仅将正在输入栏中输入内容的值发送给php,还会发送另一个JavaScript变量。修改javascript以获得两个查询字符串
的代码如下:
function showFriends(str)
{
var cake = document.getElementById("cake");
if(str.length == 0)
{
document.getElementById("livesearch1").
innerHTML = "";
document.getElementById("livesearch1").
style.border="0px";
return
}
xmlHttp=GetXmlHttpObject()
var url="petition_send.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if(xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")
{
document.getElementById("livesearch1").
innerHTML=xmlHttp.responseText;
document.getElementById("livesearch1").
style.border="1px solid #A5ACB2";
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
//Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
我需要的VAR URL等同于 “petition_send.php petition_ID =蛋糕&?”
,但是由于某种原因,没有按代码”当我这样写时,它就会起作用。
有什么想法?
写它像什么?举一个例子。 – Hamish 2010-11-15 19:29:17
如果你使用像jquery yui mootools等ajax库,它会容易得多...它们是一个选项吗? – generalhenry 2010-11-15 19:30:01
你的SEMICOLONS是什么?!?!?! (分号插入#ftf) – 2010-11-15 19:30:14