ASP.NET MVC3 and jQuery.jTable / Microsoft JScript runtime error: Unable to get value of the property 'length': object is null or undefined

StackOverflow https://stackoverflow.com/questions/13606254

  •  03-12-2021
  •  | 
  •  

Im trying to setup a table using the jQuery jTable plugin.

Atm. it's very basic. But I can't get it working. I get a JScript runtime Error every time i try and load the table.

My script looks like this:

$(document).ready(function () {

     var listURL= $('#EnvTableContainer').attr('data-list-url');
     var deleteURL = $('#EnvTableContainer').attr('data-delete-url');
     var updateURL = $('#EnvTableContainer').attr('data-update-url');
     var createURL = $('#EnvTableContainer').attr('data-create-url');

    $('#EnvTableContainer').jtable({
        title: 'Environments',
            actions: {
                listAction: listURL,
                deleteAction: deleteURL,
                updateAction: updateURL,
                createAction: createURL
            },
            fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    Name: {
                        title: 'Name',
                        width: '50%'

                    }
            }
    });

    $('#EnvTableContainer').jtable('load');
});

When I try and run it, it breaks and stops in jquery-1.8.0-min.js file on this:

var e,f=0,g=a.length,h=g===b

Anyone know what is the problem? I have been looking at the API for jQuery.jTable. But can't find anywhere, that the length can be set.

有帮助吗?

解决方案

Probably you are returning wrong formatted result. listAction URL must return a json object as shown jTable's documantation: http://jtable.org/ApiReference#act-listAction

其他提示

I ended up on this page from following this wonderful guide. http://www.codeproject.com/Articles/277576/AJAX-based-CRUD-tables-using-ASP-NET-MVC-3-and-jTa

If you happen to be following this awesome guide and end-up getting a similar error, pay attention to the caps-sensitive nature of javascript when creating your jTable instance. I had a key field of "EmployeeId" instead of "EmployeeID" and Visual Studio gave the wonderful error.

Unhandled exception at line 446, column 13 in localhost:58594/Scripts/jtable/jquery.jtable.js

0x800a138f - Microsoft JScript runtime error: Unable to get value of the property 'data': >object is null or undefined

Double check the structure of your jTable instance.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top