Answer the question
In order to leave comments, you need to log in
Why is the AJAX script not working correctly?
$('#search').on('click', function () {
$.ajax({
type: 'POST',
url:'test',
data: {
myDate: $('#data').val()
},
success: function (data) {
if (data == 'no records' || data == 'Invalid date')
{
$('p.alert').show();
$('p.alert').html('<strong>Warning!</strong> '+data);
setTimeout(alertControl, 3000);
}
else {
data = JSON.parse(data);
$('#myTable').empty();
$.each(data, function (index, value) {
$('#myTable').append("<tr class='text-left'>");
$('#myTable').append("<td style='padding: 10px;'>" + value['row1'] + "</td>");
$('#myTable').append("<td style='padding: 10px;'>" + value['row2'] + "</td>");
$('#myTable').append("<td style='padding: 10px;'>" + value['row3'] + "</td>");
$('#myTable').append("<td class='padding'><button id='delRow' class='btn btn-danger' data-index='"+index+"' data-id='"+value['id']+"'>X</button></td>");
$('#myTable').append("</tr>");
});
}
}
});
});
$('#derRow').on('click', function () {
alert($(this).attr('data-id'));
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question