jQWidgets Forums

jQuery UI Widgets Forums Grid Grid not getting remote JSON

Tagged: 

This topic contains 5 replies, has 3 voices, and was last updated by  JoeBooth 12 years ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • Grid not getting remote JSON #22807

    rafiepstein
    Member

    Hi,
    I am in the process of using the grd for the first time, following the documentation (http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/index.htm#demos/jqxgrid/bindingtojson.htm). The local Array sample worked fine.

    I am now trying a simple JSON (from a server).

    The problem: the expected AJAX request to the server to get the data does not fire, as evident by FireBug console.

    The grid shows up empty and there are no errors in FireBug console.

    This is my sample code

            $(document).ready(function () {
                var url = "/services/ajax/get_testJsonFoods";
                var source = {
                    dataype: "json",
                    datafields: [
                        { name: 'name' },
                        { name: 'type' },
                        { name: 'calories' },
                        { name: 'totalfat' },
                        { name: 'protein' },
                    ],
                    id:'id',
                    url : url
                    //root: 'Rows'
    
                };//source
                var dataAdapter = new $.jqx.dataAdapter(source, {
                    downloadComplete: function (data, status, xhr) {
                        console.log('complete:' + status);},
                    loadComplete: function (data) {
                        console.log('loadcomplete'+data);},
                    loadError: function (xhr, status, error) {
                        console.log(error);}
                });
    
                $("#jqxgrid").jqxGrid(
                {
                    width: 600,
                    source: dataAdapter,
                    pageable: true,
                    autoheight: true,
                    ready: function () {console.log('Ready')},
                    columns: [
                        { text: 'Name', datafield: 'name', width: 250 },
                        { text: 'Beverage Type', datafield: 'type', width: 250 },
                        { text: 'Calories', datafield: 'calories', width: 180 },
                        { text: 'Total Fat', datafield: 'totalfat', width: 120 },
                        { text: 'Protein', datafield: 'protein', minwidth: 120 }
                    ]
                });
            }
            )
      
    
    
    Grid not getting remote JSON #22809

    Peter Stoev
    Keymaster

    Hi,

    I cannot tell what the problem on your side is, but If the URL is correct, the Ajax request should be made.

    Best Regards,
    Peter Stoev

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

    Grid not getting remote JSON #22817

    JoeBooth
    Member

    I have the exact same problem, yet strangely other JSON calls in the same website work as expected….

    Frustrating, and the lack of ideas as to what to even try is discouraging

    Grid not getting remote JSON #22818

    JoeBooth
    Member

    This never calls the AJAX method, but if I call the URL manually, I get JSON data back as expected:

            var source =
    {
    datatype: "json",
    datafields: [
    { name: 'ID', type: 'string' },
    { name: 'PlayingDate', type: 'date' },
    { name: 'HTeam', type: 'string' },
    { name: 'HomeScore', type: 'int' },
    { name: 'VTeam', type: 'string' },
    { name: "VistorScore", type: 'int' }
    ],
    id: 'ID',
    url: 'Scoring/GetScorings'
    };

    This example works fine:

        var source =
    {
    datatype: "json",
    datafields: [
    { name: 'ID', type: 'string' },
    { name: 'PlayingDate', type: 'date' },
    { name: 'PlayingTime', type: 'string' },
    { name: 'HTeam', type: 'string' },
    { name: 'HomeScore', type: 'int' },
    { name: 'VTeam', type: 'string' },
    { name: "VistorScore", type: 'int' },
    { name: "FieldName", type: 'string' },
    { name: "HTMLScoreReport", type: 'string' },
    { name: "WeekNo", type: 'int' }
    ],
    id: 'ID',
    url: 'Sched/GetSched'
    }

    Running the JSON URL’s manually return the proper result… If I put a breakpoint in each, the second breakpoint gets reached, but the first one doesn’t. Any clues, suggestions, ideas, etc would be most appreciated…

    Grid not getting remote JSON #22829

    Peter Stoev
    Keymaster

    Hi,

    The dataAdapter has loadError callback which returns the error in the Ajax call. You may use it for debugging your scenario. Also make sure that the data files are in the same domain. Otherwise, you should use “jsonp” as a datatype.

    Best Regards,
    Peter Stoev

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

    Grid not getting remote JSON #22832

    JoeBooth
    Member

    Thanks for the suggestions, I’ll give them a try…

    Strange thing is that one works and one doesn’t..

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

You must be logged in to reply to this topic.