繁体   English   中英

使用 Django 中的 JavaScript 将数据发送到数据库

[英]Sending data to database with JavaScript in Django

我需要为这段代码编写一个兼容的算法,但我做不到。 如何将数据发送到后端? 我正在使用 bootstable.js 表

HTML 表:

<table class="table table-bordered" id="table-list">
<thead>
  <tr>
    <th></th>
    <th>Name</th>
    <th>Slug</th>
    <th>Email</th>
  </tr>
</thead>
<tbody>
  {% for chart in charts %}
  <tr>
    <th id="id">{{chart.id}}</th>
    <td class="editable" id="name">{{chart.name}}</td>
    <td class="editable" id="slug">{{chart.slug}}</td>
    <td>john@example.com</td>
  </tr>
  {% empty %}
  <p>No data</p>
  {% endfor %}
</tbody>
</table>

这是我的 JavaScript 代码。 我尝试自己尝试一些方法,但没有奏效

<script src="{% static 'npe_cp/js/bootstable.js' %}"></script>
<script>
//apply
$("#table-list").SetEditable();
$('#addRow').click(function() {
  rowAddNew('table-list');
});

$('#bAcep').on('click', function(){
  // var id=$("#id").val();
  // var name=$("#name-44").val();
  // var slug=$("#slug-44").val();
  let name=document.querySelector('#name')
  console.log(id, name, slug, 'Hello World')
  $.ajax({
      url:"/chart/edit",
      type:"POST",
      data:{
        "id":id,
        "name":name,
        "slug":slug,
      },
    })
});

这正是桌子的样子。 我想更新、创建和删除操作。 但我没有得到数据。

在此处输入图像描述

使用 Django Forms 填充数据库,可以轻松执行 CRUD 操作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM