I have created two scripts for managing a list. One for adding a li element in the page and saving it to the database, and the other one, for removing it. The fact is, when I create a li element, the second script (remove one), doesn't take effect on it (I must update the page to remove it). How can I make it work?
I leave you both scripts:
Adding:
function afegir() {
var fnom=document.getElementById('compranom').value;
var fnum=document.getElementById('quantitat').value;
$.ajax({
data: {
"nom": fnom,
"num":fnum
},
url: 'afegir.php',
type: 'post',
beforeSend: function () {
},
success: function (response) {
if(response!="-1") {
$('.llista').append('<li value="'+fnum+'" id="'+response+'" >'+fnom+'</li>');
}
else{
alert('Error');
}
}
});
}
Removing:
$(document).ready(function(){
$(".list li").click(function() {
var fid=$(this).attr('id');
$.ajax({
data: {
"id": fid
},
url: 'treure.php',
type: 'post',
beforeSend: function () {
},
success: function (response) {
if(response=="si") {
$("#"+fid+"").remove();
}
else{
alert('Error');
}
}
});
});
});
Thank you for your help.
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /home/s120321b/public_html/afegir.php on line 9
` – Feb 20 '13 at 13:58