Delete only works once

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Delete only works once



I'm having an issue with this piece of code.


if (attributeName == 'id')

var loadUrl = "http://localhost:8000/OB_ViewDetails/";
$.ajaxSetup (
cache: false
);

$("#discard").click(function()
var id = dataValue;
// alert(id);

$.ajax(
url: 'deleteob/' + id
// success:alert
).done(function(data)

$("#obfull").load(loadUrl + ' #obfull > *', function(responseText)
if(responseText != '') $('#msg').append('<p class="alert alert-success">delete successful</p>')
.children().delay(2000).fadeOut('slow');
);

);

);




Using the .load function from jQuery. The problem is that my data works only on the first call, but not on the 2nd one.


.load



I use this to delete the selected item from the list. from the modal.



What I want is to continue the process of deleting the selected list items.





What is the value of dataValue? Where and how it generated?
– Chayim Friedman
Aug 13 at 8:33


dataValue





Is the object with ID discard inserted dynamically?
– mplungjan
Aug 13 at 8:33





@ChayimFriedman .that is the ID value. to pass for selecting id from ob_details table to delete
– chimichi004
Aug 13 at 8:40





each list-item has delete button . I don't have a problem of passing data. I'm just worried that my delete function (button) won't work on the second time. I need to manually refresh in order the delete function (button) will work
– chimichi004
Aug 13 at 8:42




1 Answer
1



Delegate you click event


$("body").on("click","#discard",function()

var id = dataValue;
// alert(id);

$.ajax(
url: 'deleteob/' + id
// success:alert
).done(function(data)

$("#obfull").load(loadUrl + ' #obfull > *', function(responseText)
if(responseText != '') $('#msg').append('<p class="alert alert-success">delete successful</p>')
.children().delay(2000).fadeOut('slow');
);

);
);





What happens if i use this .on . i've read about this .delegate() / .live() but im not quite understand..
– chimichi004
Aug 13 at 8:45







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS