我想用不同的動作添加3個按鈕。我已經做出了處理這些操作的PHP代碼,但爲了實現我需要的這些操作,需要使用ajax和方法GET來添加2個參數:id和act。我以一種非常原始的方式做到了這一點!它不工作,因爲它只是變得第一id="act"
(在這種情況下是刪除),不管我點擊!:幫助AJAX中的3個按鈕
<form>
<input type="hidden" id="act" value="delete">
<input type="hidden" id="id" value="'.$row['order_id'].'">
<input type="button" id="delete" value="delete" onclick="ajaxFunction()">
</form>
<form>
<input type="hidden" id="act" value="edit">
<input type="hidden" id="id" value="'.$row['order_id'].'">
<input type="button" id="edit" value="edit" onclick="ajaxFunction()">
</form>
這裏是AJAX功能:
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.myForm.time.value = ajaxRequest.responseText;
}
}
var id = document.getElementById(\'id\').value;
var act = document.getElementById(\'act\').value;
var queryString = "?id=" + id + "&act=" + act;
ajaxRequest.open("GET", "classes/ajaxed/reservation_functions.php" + queryString, true);
ajaxRequest.send(null);
}
//-->
</script>
所以我的問題是如何使這3個按鈕與刪除,編輯,打印和每一個與它發送GET方法適當的ID和行動(編號&行爲)?
'VAR ID =的document.getElementById(\ 'ID \')值;' - 爲什麼。你是否在逃避這些引號?而'alert(「你的瀏覽器壞掉了!」);'對於使用不支持AJAX的古老瀏覽器的人來說對他們不是很有幫助。 – ThiefMaster 2011-05-22 14:45:52