2009-10-28 57 views
0

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

+0

您是否安装了Firefox扩展Firebug? (或者在您选择的浏览器中使用一个等效的JS控制台。)这可以帮助您了解正在发生的事情。 – 2009-10-28 12:43:26

回答

1

我认为这部分在onclick输入

update_program($i, $j, this.input.date.value) 

应该

update_program($i, $j, this.value) 

而且,考虑使用jQuery,它使阿贾克斯容易得多。和其他一切太:P

function update_program(row, target, value) { 
    $.get('update.php', {row:row, target:target, nfv:value}); 
} 

而且,你正在使用time和您的参数是功能value,对不对?

+0

作出了改变......似乎没有任何效果。林甚至不知道什么事情发生时,我做了 – mrpatg 2009-10-28 11:57:04

+0

编辑,仍然没有影响 – mrpatg 2009-10-28 12:09:03

相关问题