Using an ajax POST return as the source for a datatable
Using an ajax POST return as the source for a datatable
glat
Posts: 2Questions: 0Answers: 0
I have an ajax post that returns a json dataType. When 'success' is returned I hide a form and show the datatable. What I want to do is use the json return as the source for my datatable.
Is this possible? Every example I've seen either uses sAjaxSource or an explicit declaration of the aaData format. The intent: The ajax post either inserts the form data into the database, or if duplicates are detected in the database (nothing in the data is unique) the form is hidden, the table revealed, and the user is asked questions about the data in the table.
The ajax call:
[code]
var data = 'statusid=' + statusid.val() + ....
$.ajax({
url: "insert_2.php",
type: "POST",
data: data,
cache: false,
dataType: "json",
success: function(json_data, status){
if (status == 'success') {
$('#default_form_view').fadeOut(500, function() {
$('#update_table').fadeIn('slow');
[/code]
Is this possible? Every example I've seen either uses sAjaxSource or an explicit declaration of the aaData format. The intent: The ajax post either inserts the form data into the database, or if duplicates are detected in the database (nothing in the data is unique) the form is hidden, the table revealed, and the user is asked questions about the data in the table.
The ajax call:
[code]
var data = 'statusid=' + statusid.val() + ....
$.ajax({
url: "insert_2.php",
type: "POST",
data: data,
cache: false,
dataType: "json",
success: function(json_data, status){
if (status == 'success') {
$('#default_form_view').fadeOut(500, function() {
$('#update_table').fadeIn('slow');
[/code]
This discussion has been closed.
Replies
[code]
$('#form_insert').submit(function () {
var statusid = $('select[name=statusid]');
var teamid = $('select[name=teamid]');
var numbertext = $('input[name=numbertext]');
var milestoneid = $('select[name=milestoneid]');
var datediscoveredtext = $('input[name=datediscoveredtext]');
var discoveredbyid = $('select[name=discoveredbyid]');
var fixidtext = $('input[name=fixidtext]');
var dateappliedtext = $('input[name=dateappliedtext]');
var riskid = $('select[name=riskid]');
var descriptiontext = $('textarea[name=descriptiontext]');
var historytext = $('textarea[name=historytext]');
var resulttext = $('textarea[name=resulttext]');
nTable = $('#hotfix_update_table').dataTable( {
"sDom": '<"H"TCfr>t<"F"i>',
"bPaginate": false,
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"bScrollCollapse": true,
"bAutoWidth": false,
"sScrollY": "400px",
"sScrollX": "100%",
"sScrollXInner": "110%",
"sAjaxSource": "insert_2.php",
"fnInitComplete": function ( oSettings ) {
},
"fnServerData": function(sSource, aoData, fnCallback) {
aoData.push( {"name": "statusid", "value": statusid.val() } );
aoData.push( {"name": "teamid", "value": teamid.val() } );
aoData.push( {"name": "numbertext", "value": numbertext.val() } );
aoData.push( {"name": "milestoneid", "value": milestoneid.val() } );
aoData.push( {"name": "datediscoveredtext", "value": datediscoveredtext.val() } );
aoData.push( {"name": "discoveredbyid", "value": discoveredbyid.val() } );
aoData.push( {"name": "fixidtext", "value": fixidtext.val() } );
aoData.push( {"name": "dateappliedtext", "value": dateappliedtext.val() } );
aoData.push( {"name": "riskid", "value": riskid.val() } );
aoData.push( {"name": "descriptiontext", "value": descriptiontext.val() } );
aoData.push( {"name": "historytext", "value": historytext.val() } );
aoData.push( {"name": "resulttext", "value": resulttext.val() } );
$.ajax({
url: sSource,
type: "POST",
data: aoData,
dataType: "json",
success: fnCallback
});
},
} );
return false;
});
[/code]
Firefox is showing a json response in the correct format, but my datatable is displaying no rows.