2017-01-05 4 views
0

Wenig neu zu JS und eher Zeug mit etwas. Ich habe eine Ajax-Anfrage, die meine JSON-Daten und Orte in eine Tabelle einträgt und versucht, dynatable.js zu integrieren, aber nicht sicher, wie dies am besten funktioniert.AJAX JSON Anruf mit Dynatable verschmelzen - Jquery

Aktuelle JS:

$(function() { 
    'use strict'; 

    //global 
    var current_file_index = 0; 

    // Initialize the jQuery File Upload widget: 
    $('#fileupload').fileupload({ 
     // Uncomment the following to send cross-domain cookies: 
     //xhrFields: {withCredentials: true}, 
     url: 'server/php/', 
     prependFiles:true 
    }).on('fileuploadsubmit', function (e, data) { 
     //data.formData = {date: data.files[0].date}; 
     data.formData = data.context.find(':input').serializeArray(); 
    }); 

    // Load existing files: 
    $('#fileupload').addClass('fileupload-processing'); 

    $.ajax({ 
     // Uncomment the following to send cross-domain cookies: 
     //xhrFields: {withCredentials: true}, 
     url: $('#fileupload').fileupload('option', 'url'), 
     dataType: 'json', 
     context: $('#fileupload')[0], 
     prependFiles:true, 

    }).always(function() { 
     $(this).removeClass('fileupload-processing'); 
    }).done(function (result) { 
     $(this).fileupload('option', 'done').call(this, $.Event('done'), {result: result}); 
    }); 

}); 

Dynatable JS:

$('#remote').dynatable({ 
    dataset: { 
     ajax: true, 
     ajaxOnLoad: true, 
     ajaxUrl: '/server/php/index.php', 
     files: [] 
    } 
}); 

Wenn ich beide zusammen bekomme ich diejenigen verwenden:

Uncaught TypeError: Cannot read property 'length' of null at Records.count (jquery.dynatable.js:694) at RecordsCount.create (jquery.dynatable.js:708) at RecordsCount.attach (jquery.dynatable.js:734) at RecordsCount.init (jquery.dynatable.js:704) at Object.build (jquery.dynatable.js:186) at Object.init (jquery.dynatable.js:142) at HTMLTableElement. (jquery.dynatable.js:1673) at Function.each (jquery.min.js:2) at n.fn.init.each (jquery.min.js:2) at n.fn.init.$.fn.dynatable (jquery.dynatable.js:1671)

Wenn ich den folgenden Code, Art funktioniert, aber fügt nur die Suche, 0 von 0 usw. hinzu. Ich versuche die Tabelle zu sortieren und lösche alle Daten, wie sie über den Ajax geladen wurden ... littl Das ist schwer zu erklären. In einer aber Shell denke ich, dass ich sie besser integrieren muss, damit sie zusammen arbeiten.

$ ('# remote'). Dynatable();

Ich werde sehen, ob ich kann Setup eine Geige für dieses

+1

Was ist das Problem? Gibt es da irgendwo eine Frage? –

+0

Ich scheine einen Fehler zu bekommen, wenn ich beide zusammen benutze: Uncaught TypeError: Kann die Eigenschaft 'length' von null nicht lesen bei Records.count (jquery.dynatable.js: 694) bei RecordsCount.create (jquery.dynatable.js: 708) bei RecordsCount.attach (jquery.dynatable.js: 734) bei RecordsCount.init (jquery.dynatable.js: 704) bei Object.build (jquery.dynatable.js: 186) bei Object.init (jquery.dynatable.js: 142) bei HTMLTableElement. (jquery.dynatable.js: 1673) bei Function.each (jquery.min.js: 2) bei n.fn.init.each (jquery.min.js: 2) – James

+0

Und Sie sind sicher, dass Sie eine json Antwort bekommen? –

Antwort

0

Für alle, die Lösung wollen hierfür siehe unten:

$.ajax({ 
    // Uncomment the following to send cross-domain cookies: 
    //xhrFields: {withCredentials: true}, 
    url: $('#fileupload').fileupload('option', 'url'), 
    dataType: 'json', 
    context: $('#fileupload')[0] 

}).always(function() { 
    $(this).removeClass('fileupload-processing'); 
}).done(function (result) { 
    $(this).fileupload('option', 'done').call(this, $.Event('done'), {result: result}); 
    $('.table-striped').dynatable({ 
     dataset: { 
     files: result, 
     dataType: 'text' 
     } 
    }); 
});