xmlHttpRequest和操作表?

时间:2015-08-15 18:36:58

标签: javascript php html mysql

我目前使用java脚本函数根据选择加载内容,这里是函数的一个例子

function loadActions2(id,value,title) {
        var url = title+"?value="+value;
}

if (window.XMLHttpRequest) {
    xmlhttp=new XMLHttpRequest();
} else {
    xmlhttp=new ActiceXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        divtarget.innerHTML=xmlhttp.responseText;
    }
}

xmlhttp.open("GET",url,false);
xmlhttp.send();
}

这将加载一个包含所需内容的php文件。 我的主站点看起来像这样

<table>
    <tr>
      <td> Text 1234</td>
      <td>
       <label onclick"loadActions2('id','value','title')"> Click here</label>
      </td>
    </tr>
</table>

并且加载的php文件包含另一个表。 现在,我正在寻找一个解决方案,将文件的内容直接添加到表中,所以这意味着,我的php文件看起来像这样

<tr>
   <td>Text 999</td>
</tr>

应该直接添加到现有表中,而不是单独的div / table。

这可能吗?

1 个答案:

答案 0 :(得分:3)

为表分配id,当请求成功时,将HTML附加到表中:

xmlhttp.onreadystatechange = function() {
  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
    document.getElementById("mytable").innerHTML += xmlhttp.responseText;
  }
}
相关问题