我尝试使用ajax从数据库获取数据,我认为我在ajax网址中存在问题
我的json结果在这个网址
http://127.0.0.1:8888/manage/JournalVente.php?method=jason&popup=1
结果是
[{"IDCUSTOMER":"255","NBORDER":"10","DATE_SAVE":"0000-00-00 00:00:00","DATE_SEND":"0000-00-00 00:00:00","COMPANY":"haboussa","PAYMENT_TYPE":"CHQ","TOTAL_TTC":"0.00"}]
我的代码是
function Load() {
$('#update_panel').html("<img src='../static/loading.gif' />");
$.ajax({
url: 'http://127.0.0.1:8888/manage/JournalVente.php?method=jason&popup=1',
type: 'GET',
dataType: 'json',
success: function (d) {
// alert(d.length);
if (d.length > 0) {
var $data = $('<table></table').addClass('table table-responsive table-striped');
var header = "<thead><tr><th width='5px' class='no_sort'></th><th width='5px' class='no_sort'></th><th width='5px' class='no_sort'></th><th>Référence</th><th>Date saisie</th><th>Date échéance</th><th>Client</th><th>Type de paiement</th><th>Montant</th></tr></thead>";
$data.append(header);
$.each(d, function (i, row) {
//alert(row.FIRSTNAME);
var $row = $('<tr/>');
$row.append($('<td/>').html("<a href='invoice.php?idcustomer=" + row.IDCUSTOMER + "'&idorder=" + row.IDORDER + "'&print=1' target='_blank' ><img src='../static/css/actions/pdf.png' border='0' /></a>"));
$row.append($('<td/>').html("<a href='?method=update_details&idcustomer=" + row.IDCUSTOMER + "'&idorder=" + row.IDORDER + "'><img src='../static/css/actions/edit.png' border='0' /></a>"));
$row.append($('<td/>').html("<a href='?method=delete&idorder=" + row.IDORDER + "'&popup=1' class='popup-delete'><img src='../static/css/actions/delete.png' border='0' /></a>"));
$row.append($('<td/>').html(row.NBORDER));
$row.append($('<td/>').html(row.DATE_SAVE));
$row.append($('<td/>').html(row.DATE_SEND));
$row.append($('<td/>').html(row.COMPANY));
$row.append($('<td/>').html(row.PAYMENT_TYPE));
$row.append($('<td/>').html(row.TOTAL_TTC));
$data.append($row);
});
alert($data)
$('#update_panel').html($data);
}
else {
var $noData = $('<div/>').html('No Data Found!');
$('#update_panel').html($noData);
}
},
error: function () {
alert('Error! Please try again.')
}
});
}
它总是给我警报错误!请再试一次。