我有一系列動態生成的輸入,我需要在php文件中爲我更新ajax,一旦用戶點擊輸入。使用ajax發送更改爲輸入後的PHP文件
我認爲我有正確的代碼,但它不工作的原因超出我的理解。我是一個完整的javascript/ajax noob,所以要溫柔。
的JS/AJAX:
<script type="text/javascript">
// Initialize the object:
var ajax = false;
// Create the object...
// Choose object type based upon what's supported:
if (window.XMLHttpRequest) {
// IE 7, Mozilla, Safari, Firefox, Opera, most browsers:
ajax = new XMLHttpRequest();
} else if (window.ActiveXObject) { // Older IE browsers
// Create type Msxml2.XMLHTTP, if possible:
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) { // Create the older type instead:
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) { }
}
}
function update_program(row, target, value) {
if (ajax) { // Confirm that the object is usable
ajax.open('get', 'update.php?row=' + encodeURIComponent(row) + '&target=' + encodeURIComponent(target) + '&nfv=' + encodeURIComponent(value)); // Call the PHP script using GET, pass the variable
//ajax.onreadystatechange = handle_programupdate; // Function that handles the response
ajax.send(null); // Send the request
}
}
</script>
而對於動態輸入字段
echo "<td><input type=text value=\"$value\" name=\"date\" onblur=\"update_program($i, $j, this.input.date.value);\" class=med></td></td>";
行計數的PHP是$ i,而該場數爲附加$ J。所以我需要發送的數據是行,字段(目標)和輸入的修改值。
輸入被安排在一個表中有很多很多(變化的行,63場)。每個字段可以是文本輸入,也可以是文本區域。如何讓他們在用戶更改後提交給php文件?
您是否安裝了Firefox擴展Firebug? (或者在您選擇的瀏覽器中使用一個等效的JS控制檯。)這可以幫助您瞭解正在發生的事情。 – 2009-10-28 12:43:26