datatable ajax data

datatable ajax data

chirochiro Posts: 16Questions: 8Answers: 0

Hi.

I replaced function ajax with a datatable.

$(document).ready(function() {
getUserList();
}


function getUserList(){
    $.ajax({
        url : "userList.json",
        success:function(data){
            var html = '';
            for(key in data){
                html += '<tr>';
                html += '<td>'+data[key].name+'<td>';
                html += '<td>'+data[key].email+'<td>';
                html += '<tr>';
            }
            $("#div").empty();
            $("#div").append(html)
        }
    })
}

I have succeeded in changing the source above as below.


$(document).ready( function () {
    var table = $( '#userTable' )
    .addClass( 'nowrap' )
    .dataTable( {
        responsive: true,
        ajax: {
            'url': 'userList.json’,
            'dataSrc': ''
        },
        columns: [
            {'data': 'name'},
            {'data': 'email'}
        ]
    } );
} );

But I don't know how to change the data in the source below...
Where should I add something to my data table?


var global_UserOrder = null;
 
$(document).ready(function() {
    global_UserOrder = order;
    getUserList();
}
 
function getUserList(order){
    global_UserOrder = order;
    $.ajax({
        //this
        data : {
            order : order,
        },
        //
        url : "userList.json",
        success:function(data){
            var html = '';
            for(key in data){
                html += '<tr>';
                html += '<td>'+data[key].name+'<td>';
                html += '<td>'+data[key].email+'<td>';
                html += '<tr>';
            }
            $("#div").empty();
            $("#div").append(html)
        }
    })
}

Thanks. ^--------^

Answers

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921
    edited January 2020

    Use ajax.data. There are examples for both static and dynamic data. The ajax docs explain:

    As an object, the ajax object is passed to jQuery.ajax allowing fine control of the Ajax request.

    Kevin

This discussion has been closed.