简体   繁体   中英

Sending data to database with JavaScript in Django

I need to write a compatible algorithm for this code, but I can't. How can I send data to backend? I am using bootstable.js for table

HTML table:

<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>

And this is my JavaScript code. I tried to try some methods myself but it didn't work

<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,
      },
    })
});

This is exactly what the table looks like. I want to update, create, and delete operations. But I am not getting the data.

在此处输入图像描述

Use Django Forms to populate the database, makes it easy to perform CRUD operations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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