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. ^--------^

This question has accepted answers - jump to:

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    But I don't know how to change the data in the source below...

    I'm not following, sorry. The middle example would load the data into the DataTable - I'm not sure what you're trying to do.

    Colin

  • chirochiro Posts: 16Questions: 8Answers: 0

    I succeeded in replacing the first example with the second.
    I want to replace the third example with a datatable like the second.
    I don't know how to do this
    data : {
    order : order,
    },

    thanks your reply

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921
    Answer ✓

    You should read through the ajax docs. It states:

    As an object, the ajax object is passed to jQuery.ajax

    And points you to using ajax.data. The examples show how to add static data or adding dynamic data using a function.

    Kevin

  • chirochiro Posts: 16Questions: 8Answers: 0

    I finally succeeded.

    Not this ↓
    .dataTable( {
    ajax: {

    In the third example, run the datatable inside success: function (data)

    thanks your reply ^___^

This discussion has been closed.