我有這個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