[Django]-AJAX function is not getting the id

4👍

Pass the returned data to your success function as below,

success:function(data) {
...
  var button = $('<button class="reo"  onclick="delete_product('+ data +')" id="my" value="">Delete</button>');
...
}

Your view should be returning the new created id in the HttpResponse. For example (assuming python/django backend),

Return HttpResponse(new_record.id, status=200)

Hope this helps!

👤devdob

Leave a comment