我有一系列动态生成的输入,我需要在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