Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将tbody内容插入数据库_Javascript_Java_Html_Jsp - Fatal编程技术网

Javascript 将tbody内容插入数据库

Javascript 将tbody内容插入数据库,javascript,java,html,jsp,Javascript,Java,Html,Jsp,我有以下Java脚本函数: var tabBody, row, cell; function updateTable() { tabBody = document.getElementById("editable"); row = document.createElement("tr"); cellID = document.createElement("td"); cellname = document.createElement("td"); c

我有以下Java脚本函数:

var tabBody, row, cell;

function updateTable()
{
    tabBody = document.getElementById("editable");
    row = document.createElement("tr");

    cellID = document.createElement("td");
    cellname = document.createElement("td");

    cellID.innerHTML = document.forms['myForm1'].elements[1].value;
    cellname.innerHTML = document.forms['myForm1'].elements[0].value;

    row.appendChild(cellID);
    row.appendChild(cellname);

    if (tabBody.childNodes.length == 10)
    {
        tabBody.removeChild(tabBody.childNodes[0])
    }

    document.getElementById("mytb").style.display = "block";

    tabBody.appendChild(row);
}
将数据添加到输入文本时会出现tbody,如:


如何将这些数据插入数据库?

我认为您必须循环您身体的每个元素并获取每个值。 例如,使用jquery:

// this will get all lines of your table
$("#editable tr").each(function(index,element){
  // here element is the current line (<tr>) of the loop

   // here we get all <td> of <tr>
  $(element).children().each(function(tdIndex,tdElement){
   // here we get the value of current <td>
   var value = $(tdElement).html();// value of td content
  });
});
//这将获取表中的所有行
$(“#可编辑tr”)。每个(函数(索引,元素){
//元素是循环的当前行()
//我们都到了
$(元素).children().each(函数(tdIndex,tdElement){
//这里我们得到电流的值
var value=$(tdElement.html();//td内容的值
});
});

将数据返回到服务器可以使用ajax调用

例如:

var jqxhr = $.ajax( "receivedata.jsp?p1=" + document.forms['myForm1'].elements[1].value + "&p2=" + document.forms['myForm1'].elements[0].value )
  .done(function() {
       alert( "success" );
  })
  .fail(function() {
      alert( "error" );
  })
  .always(function() {
     alert( "complete" );
  });
以上摘录自


如果在服务器端使用JSP,您将获得p1和p2参数。

哪些数据和什么数据库?我想将tbody中的名称和ID插入数据库中的表中。您在服务器上已经有数据库了吗?当然,我也有一个表来插入这些数据。提及您使用的数据库吗?