I'm devloping a tool with MySQL, HTML5, jQuery and Json. On my website I have 3 tables, but one of them has to be transposed. So I write this:
$(document).ready(function () {
$('#druckerdetails').dataTable({
"bPaginate": false,
"bLengthChange": false,
"bFilter": false,
"bSort": false,
"bInfo": false,
"bAutoWidth": false,
"bProcessing": true,
"bServerSide": false,
"sAjaxSource": 'php/index_druckerdetails.php?druckername=RAGPLM002'
});
$(function () {
var table = $('#druckerdetails');
alert('Besten Dank, dass Sie isyPrint benutzen :)');
table.find('thead tr').detach().prependTo(table.find('tbody'));
var t = table.find('tbody').eq(0);
var r = t.find('tr');
var cols = r.length;
var rows = r.eq(0).find('td,th').length;
var cell, next, tem, i = 0;
var tb = $('<tbody></tbody>');
while (i < rows) {
cell = 0;
tem = $('<tr></tr>');
while (cell < cols) {
next = r.eq(cell++).find('td,th').eq(0);
tem.append(next);
}
tb.append(tem);
++i;
}
table.find('tbody').remove();
$(tb).appendTo(table);
$(table)
.find('tbody tr:eq(0)')
.detach()
.appendTo(table.find('thead'))
.children();
table.show();
});
});
With this alert all is fine and works, because the php-file has enough time to return the Json-String. But if there is no alert, the JavaScript doesn't wait for the data of the php whith the MySQL-query. So the data is missing in on the website.
Without alert: http://www.computerbase.de/forum/attachment.php?attachmentid=359923&d=1377067918
So here is the timeline (isyprint_home.js & index_druckerdetails.php): http://www.computerbase.de/forum/attachment.php?attachmentid=359927&d=1377072271
So what I have to do, that the js-file waits until the json-string was returned?
Thanks and sorry for my bad English