STEPS
1. You will add a name attribute to all your input fields.
2. Add the crsf_token django template in-built filter to support 'POST'
3. Change your form's method to 'POST'
4. Add an action attribute and set it to your view
5. Then the JQUERY part will be as follows
6. Don't forget to give your form ad ID
Then
 $("#form_id").submit(function(e){
e.preventDefault()  //prevent the  default submit behaviour of a form
let data = $(this).serialize() // this picks all data basing on the name
attribute including the csrf_token
let URL = $(this).attr('action') //this pick the right URL like
http://localhostL:8000/add

//now perform the request
$.ajax({
url:url,
data:data,
type: "POST",
dataType: "json", // or the data type you expect from your response
beforeSend: function(){
// optional-> whatever you want to access before executing the request
// eg showing some loader
},
success: function(response){
// whatever you want to do on successful request
},
complete: () =>{
//whatever you want to do when  the request is complete
// stopping some loader
}

})
})




On Sat, Dec 4, 2021 at 1:17 PM Eugene TUYIZERE <eugenetuyiz...@gmail.com>
wrote:

> Dear Colleagues,
>
> I have data in the table. I want to get the rows value and save them in
> the database. How can I do this with jquery?
> The table I have is like this
> [image: image.png]
> This is what I have in HTML. The total is automatically calculated as I
> type the amount
>
> <table id="myTable2">
> <tr> <th width="300">Description </th>
> <th width="400">Amount</th>
> </tr>
> <tr>
> <td><span>School Fess </span></td>
> <td><input type="text" class='form-control text-right' /></td>
> </tr>
> <tr>
> <td><span>Restoration </span></td>
> <td><input type="text" class='form-control text-right' /></td>
> </tr>
> <tr>
> <td><span>School materials </span></td>
> <td><input type="text" class='form-control text-right' /></td>
> </tr>
>
> <tr>
> <td><span><b>TOTAL </b></span></td>
> <td><b><span id="total_sum_value2"></span></b></td>
> </tr>
> </table>
> --
> *Eugene*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABxpZHsPPHbpkNOBDxGofAX-0uHPfGtgXYpHwoQo5iaqGOg9rg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CABxpZHsPPHbpkNOBDxGofAX-0uHPfGtgXYpHwoQo5iaqGOg9rg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>


-- 
jet

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMjc0xUTy_CaWpkxuMrcjytXaLYHXBTWoSuLrdp4-bCLW1H4%3Dw%40mail.gmail.com.

Reply via email to