I
I
IvanOne2013-12-14 17:28:14
JavaScript
IvanOne, 2013-12-14 17:28:14

Ajax question?

There is this code:

$(document).ready(function() {

$('#add').click(function() {
if($('#group').val()==='')
{
alert('Enter a title!');
return false;
}
var group=$('#group').val();

$.ajax({
type:"get",
url:"addGroup.php?data="+ group,
datatype:"html",
success:function(response){
$('#groups').append(response);
$('#group').val("");
},
error:function (xhr, ajaxOptions, thrownError){
//display the error
alert(thrownError);
}

});
});

$('.del').click(function(){
var buttonId=this.id;
$.ajax({
type:"get",
url:"delGroup.php?id="+buttonId,
datatype:"html",
success:function(){
$("#cont"+buttonId).fadeOut(200) ;
},

});

});
});

The first request adds an element in which there is a delete button, the second request is just tied to this button. But when the element is generated and when the delete button is clicked, the second request does not work, if the page is reloaded, the delete button works fine. Where could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolai Vasilchuk, 2013-12-14
@Anonym

Look at .on and .delegate

I
IvanOne, 2013-12-14
@IvanOne

did with on, thanks!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question