使用jQuery AJAX将多个div中的数据插入数据库

时间:2018-08-12 16:49:13

标签: php jquery ajax

我有一个表单,允许用户按需添加输入字段,如下所示:

  <input id="addADayButton" type="button" value="Add A Day" /></br>

  <table>
        <tr>
        <th>Date</th>
        <th>1st Time</th>
        <th>2nd Time</th>
        <th>3th Time</th>
        <th>4th Time</th>
        <th>Staff Name</th>
        </tr>
  </table>

  <div id="recordGroup">
     *// the new div would add here*
  </div>

  </br></br>
  <input type="submit" value="Submit Record" /></br>
</form>

//每天添加一个div的按钮(或根据用户选择增加),div有6个输入字段

<script>

$("#addADayButton").click(function(){

  var selectDate = $("#selectDate").val();
  var timesPerDay = $("#timesPerDay").val();

  for (i=1;i<=timesPerDay;i++){

  *// all div that added use the same class*
    var newRecordDayDiv = $(document.createElement("div")).attr("class", "insertDiv");

    newRecordDayDiv.after().html(
      "<input id='recordDate' type='text' value ='"+ selectDate + "'name='recordDate' readonly/>" +
      "<input id='firstTime' type='time' name='firstTime' />" +
      "<input id='secondTime' type='time' name='secondTime' />" +
      "<input id='thirdTime' type='time' name='thirdTime' />" +
      "<input id='fourthTime' type='time' name='fourthTime' />" +
      "<input id='staff' type='text' name='staff' />"
    );
    newRecordDayDiv.appendTo("#recordGroup");
  }

 });

</script>

jquery:

def area_rectangle(width,height):

    width=int(input("Enter the width of rectangle: "))
    height=int(input("Enter the height of rectangle: "))
    area=width*height
    print area

如何使用AJAX将这些数据发布到php以插入数据库? 我已经尝试了围绕每个div class =“ insertDiv”的jquery的方法,但是失败了。 先感谢您。

0 个答案:

没有答案