jQuery UI Widgets Forums DataTable send dataTable as json via ajax

This topic contains 4 replies, has 2 voices, and was last updated by  Dimitar 10 years ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • send dataTable as json via ajax #69022

    cpuin
    Participant

    we know how to export dataTable data as json, but how to send it via ajax?
    An more importantly how to send dataTable data as json via ajax with some additional information.
    What i mean: i have inv.number, inv.data and in the dataTable rows with products.I want to mix into one json inv.number, inv.data and all dataTable data and send it via ajax.

    
    var rowData={
    
    Inv: 1,
    Operator: 2
    }
    
    var data = "insert=true&" + $.param(rowData);
    				$.ajax({
    				    dataType: 'json',
    				    url: 'json_documents.php',
    				    cache: false,
    				    data: data ....
    
    send dataTable as json via ajax #69049

    Dimitar
    Participant

    Hello cpuin,

    Here is one possible solution:

    var dataTableData = $('#jqxDataTable').jqxDataTable('getRows');
    
    $.ajax({
                dataType: 'json',
                url: 'json_documents.php',
                cache: false,
                data: {
                    insert: true,
                    Inv: 1,
                    Operator: 2,
                    records: dataTableData
                },
                ...

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    send dataTable as json via ajax #69061

    cpuin
    Participant

    Dear Dimitar,

    On thi sway the method to send is GET right?

    send dataTable as json via ajax #69082

    cpuin
    Participant

    I ‘m getting this error SyntaxError: JSON Parse error: Unexpected EOF

    When use this:

    
    var rowData = {
    	        	//credit note
    	        	OperType: 27,
    	        	Acct: 5,
    	        	GoodID: 2,
    	        	records: dataTableData
    	        	
    	        	};
    
    var data = "creditnote=true&insert=true&" + $.param(rowData);
    				console.log(data);
    				$.ajax({
    				    dataType: 'json',
    				    url: 'json_operations.php?',
    				    cache: false,
    				    data: data,
    				    success: function (data, status, xhr) { .....
    send dataTable as json via ajax #69126

    Dimitar
    Participant

    Hi cpuin,

    Yes, you can use the GET method, too.

    As for sending the data, please try adding all your parameters in a single object and pass it as the Ajax call’s data, e.g.:

    var rowData = {
        creditnote: true,
        insert: true,
        OperType: 27,
        Acct: 5,
        GoodID: 2,
        records: dataTableData
    };
    
    $.ajax({
                dataType: 'json',
                url: 'json_operations.php?',
                cache: false,
                data: rowData,
                success: function(data, status, xhr) {.....

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.