Using JavaScript to send information to Django's database

Struggling to create a compatible algorithm for this code. How do I send data to the backend while using bootstable.js for tables?

The HTML table structure is as follows:

<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><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c5afaaadab85a0bda4a8b5a9a0eba6aaa8">[email protected]</a></td>
  </tr>
  {% empty %}
  <p>No data</p>
  {% endfor %}
</tbody>
</table>

Below is the JavaScript code snippet that requires attention:

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

Describing the appearance and functionality of the table's update, create, and delete operations which are not functioning as intended.

https://i.sstatic.net/poG5Z.png

Answer №1

Django Forms can be utilized to effortlessly populate the database and simplify the process of performing CRUD operations.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Enable the input field once the checkbox has been marked

Here is a checkbox example: <div class="form-group"> <input type="checkbox" id="examination" class="form-control" name="exam" placeholder="Enter Title"> <label>Enable Exam</label> </div> Additionally, I have a disabled inpu ...

Can a website trigger an alarm on a user's iPhone without their permission?

Even though I have limited experience with HTML, CSS, and Javascript, I am curious if it is possible to create a basic website that can trigger an alarm on the user's device by simply clicking a button. For example, imagine a scenario where a user is ...

Is there a way to retrieve the zoom level in Highmaps and are there any events related to zooming in Highmaps

Is there a way to trigger a zoom event in Highmaps? Furthermore, how can the current zoom level of the map be retrieved? Adjusting the zoom level is straightforward, but extracting it proves to be more challenging. After exploring the API documentation, ...

Rendering components based on a condition of a true or false prop value

Here's a code block that I need help with: return ( <StyledActiveOptions className={classNames("lookup-active-options form-control", className)} role="button" tabIndex="0" aria-haspopup=&q ...

How can the distinctions between two bars be illustrated in high charts?

Is there a way to display different values on a new line between two bar charts using Highcharts plugins? I have created a simple bar chart in Highcharts, but I am looking to show the difference between the two bars on a new line. The concept is illustrate ...

Which entity is responsible for supplying the next() function within Express middleware?

I'm trying to understand the workings of next() in Node.js and Express middleware. While there have been previous inquiries regarding middleware operations, such as this one, I am seeking a fresh perspective. The primary query troubling me is: who s ...

javascript creating unique model instances with mongoose

I've searched through related posts without finding exactly what I need. Currently, I am working on building a backend rest API and conducting tests to collect data. Each test has its own model which is associated with collections in the database. T ...

jQuery tabs become non-functional following submission of form

I have a form contained within a jQuery tab div that is loaded using AJAX: <div id="tabs-2"> <form id="frmLogin" name="frmLogin" class="cmxform" method="post" action="actions/login.php"> <p> <label>Username& ...

Create a receipt by utilizing jQuery with dynamically generated inputs

Is there a way to insert the descriptions and amounts of invoice items into the receipt, similar to the due date? The input for this section is dynamic with multiple rows that can be added or deleted. I'm considering using a counter that increments e ...

Could it be an issue with Jquery? Maybe it's related to AJAX reload, or possibly just a case

Utilizing the following Jquery : $('#resultstable').on('click', 'tbody tr', function() { alert("helloworld") $('#resultstable tr.Selected').removeClass('Selected'); $(this).addClass('Selected'); ...

Cherrypy/Chrome: Issue with jquery ajax request remaining pending after several successful requests

My current project involves a Cherrypy server that receives a JSON array from a client via AJAX call. The server then manipulates the array and sends it back to the client. However, I've noticed an issue where after a few smooth requests, the next req ...

Looping in jQuery to dynamically generate form field JS code

Here is the HTML & JS code for form submission. The code works as expected, but I am looking to simplify the JavaScript by using a loop iteration. The only difference between 'Full Name' and 'Booking Ref no.' is the ID and Class names. ...

Issue with SWIG Python module arises specifically when deployed on Apache servers

This situation is really strange and it's driving me mad. Any assistance would be greatly appreciated! Our problem involves some underlying C codes that are being accessed by Python modules (specifically Python version 2.6, Django framework version 1 ...

Django ModelForm encountering issues with subclassed models: Error arises for one model but not for another (Error message: 'NoneType' object does not have attribute 'label')

I need some guidance regarding a django issue: These are the models I am currently using: class QItem(models.Model): isWhat = models.CharField(max_length=100, blank=True, choices=ISWHAT) slug = models.SlugField(blank=True) script = models.Ch ...

Tips for positioning the footer in HTML and CSS

footer { background-color: #000000 } .footer-nav { list-style: none; } .footer-nav li { display: inline-block; margin: 15px; font-weight: 400; font-size: 80% } .social { list-style: none; } .social li { display ...

Unable to fetch data from Array using an identifier in Angular 4

My goal is to fetch an object from an array by its id using the getItem() method. import { Injectable } from '@angular/core'; import { Http, Response } from '@angular/http'; import { Observable } from 'rxjs/Observable'; impor ...

How to Transfer Data from a Dynamic Drop-down Menu to PHP for Processing and Presentation in a Div Element on the Same Web Page

I've scoured various online resources, including StackOverflow, but haven't been able to find a solution for this issue described in the title. On my base page, I have a dynamically generated dropdown list as shown below: <div class="tipfixtu ...

Error encountered when accessing the next sibling of the current element ($(this))

Wondering why I can only see the save button when clicking edit and not the cancel button. Here is my code snippet: $(".editlink").on("click", function(e){ e.preventDefault(); var dataset = $(this).prev(".datainfo"); var savebtn = $(this) ...

Combining Arrays in AngularJS: A Step-by-Step Guide

I have two arrays with dynamic values: $scope.objectName = [{ Name: '' }]; $scope.propertiesElement = [{ Key: '', Value: '' }]; How can I concatenate these arrays to achieve the following result? [{Name:''},{ Key: ...

Steps for incorporating a smooth transition effect into a modal popup as its height dynamically increases

I need assistance with adding a transition effect to a modal popup that automatically increases in height when content is loaded. I have tried various styles, but none of them seem to be working. .tagModal{ overflow:hidden; transition:transform ...