Load/reload data from server

Load/reload data from server

ImpPhilImpPhil Posts: 12Questions: 4Answers: 0

I'm using ASP.NET MVC.

I have this which works to load the data initially

    $(document)
        .ready(function() {

            $('#users')
                .DataTable({
                    paging: true,
                    data: getUsers(),

... etc
});
});

    function getUsers() {
        var users;

        $.ajax(
        {
            url: '@Url.Action("GetUsersJavaScriptArray")',
            type: 'GET',
            cache: false,
            async: false,
            data: {
                appGuid: $('#@Html.IdFor(m => m.SelectedAppUniqueId)').val()
            },
            success: function (data) {
                users = data;
            },
            error: function () {
            },
            complete: function () {
            }
        });

        return users;
    }

But I can't work out how to reload the data when the appGuid has changed.
Using $('#users').DataTable().ajax().reload() gives me "0x800a138a - JavaScript runtime error: Function expected".

If I try to use

            $('#users')
                .DataTable({
                    paging: true,
                    ajax: {
                        url: '@Url.Action("GetUsersJavaScriptArray")',
                        type: 'GET',
                        cache: false,
                        async: false
                    },

....

That fails with a null ref exception.

Any help appreciated.

Answers

  • ImpPhilImpPhil Posts: 12Questions: 4Answers: 0

    I've solved my own question. I was missing dataSrc: ''

This discussion has been closed.