0

my below code not worked on IE 8. Its a JQGrid (treegrid) to display treegrid format from json server. it worked at firefox.

$(function () {
    "use strict";
    $("#tree").jqGrid({
        url: "http://myJSON-URL/",
        datatype: "json",

        colNames: ['id', 'Prestations'],
        colModel: [
                { name: 'id', width: 100, key: true, hidden: true },
                { name: 'name', width: 785, sortable: false }
            ],
        sortname: 'id',
        sortorder: "asc",
        hiddengrid: true,
        gridview: true,
        treeGrid: true,
        treeGridModel: "adjacency",
        ExpandColumn: 'name',
        ExpandColClick: true,
        jsonReader: { repeatitems: false, root: function (obj) { return obj; } },
        height: "auto"
    });
});

I think its AJAX cors problem. Any idea? thanx.

The json server side responsed these:

 json = [
{
    "id": "1",
    "name": "ECHANGEUR",
    "level": "0",
    "parent": "null",
    "isLeaf": false,
    "expanded": false,
    "loaded": true
},
{
    "id": "1_1",
    "name": "Intervention Aller sur Site",
    "level": "1",
    "parent": "1",
    "isLeaf": false,
    "expanded": false,
    "loaded": true
},
{
    "id": "1_1_1",
    "name": "Date et heure d'arrivée sur le site",
    "level": "2",
    "parent": "1_1",
    "isLeaf": true,
    "expanded": true,
    "loaded": true
},
{
    "id": "1_1_2",
    "name": "Consignation de l'échangeur",
    "level": "2",
    "parent": "1_1",
    "isLeaf": true,
    "expanded": true,
    "loaded": true
}

];

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
hahamed
  • 309
  • 1
  • 2
  • 12
  • It's important to know which version of jqGrid you use? Which format have input data? You should append your question with the test JSON data. I would recommend you to try to use free jqGrid 4.8. You can access it directly from [CDN](https://github.com/free-jqgrid/jqGrid/wiki/Access-free-jqGrid-from-different-CDNs) or download from [githib](https://github.com/free-jqgrid/jqGrid/archive/v4.8.0.zip). See details in [readme](https://github.com/free-jqgrid/jqGrid) and in [wiki](https://github.com/free-jqgrid/jqGrid/wiki). – Oleg Mar 10 '15 at 08:52
  • I would recommend you additionally to include `loadError` callback (see [here](http://stackoverflow.com/a/6969114/315935)) to be sure that you will see error message if any parsing problem of JSON or other Ajax errors (like CORS specific problems) exist. – Oleg Mar 10 '15 at 09:01
  • jqGrid 4.7.1. problem is not for jqGrid. my IE 8 has partial support for load via ajax. – hahamed Mar 10 '15 at 10:39

1 Answers1

1

You have just the problem with the bug specific for jqGrid 4.7.x. You can try tree demos which uses different versions of jqGrid and the same code and JSON which you posted:

demo46, demo47, demo48, demo-free-jqGrid-GitHub.

(The last one uses free jqGrid 4.8 which I published recently, see here and here).

You can verify that the demo which uses jqGrid 4.7 only have the problem in IE8 and both other demos have no problem. You can read more about the bug here or here.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • my Problem on IE8 is: i use local html file to open it. this is my ignored item to tell you. – hahamed Mar 11 '15 at 10:51
  • 1
    @hahamed: Sorry, but I don't understand what you mean. What problem you have with *local* html files? Do you can reproduce the same bug in demo47 demo? Are demos demo46 and demo48 works correctly on your test computers? If you have **local** html file then you have probably **local** file with JSON input data which you use in `url`. I did the same in my demos and I have no problem with loading. If you do have some errors *during loading* you have to include `loadError` callback (see [here](http://stackoverflow.com/a/6969114/315935)). It can be that you have pure Ajax loading error. – Oleg Mar 11 '15 at 11:22
  • I open Local html file and my local script is: `$("#tree").jqGrid({ url: "http://myJsonServer.com", datatype: "json", colNames: [...`. but treegrid did not load json on iE8 and loaded data at firefox – hahamed Mar 12 '15 at 04:42
  • @hahamed: The problem should exist not only in IE8. Corresponds to [Same-Origin-Policy](http://de.wikipedia.org/wiki/Same-Origin-Policy) you can't load Ajax data from another source as the source of HTML file. So both the server and the client have to inform explicitly Ajax that loading from another source is permitted. It the server part is already correct that you have to use correct client options in Ajax. For example `datatype: 'jsonp'` like in [the answer](http://stackoverflow.com/a/9588051/315935). – Oleg Mar 12 '15 at 06:10
  • @hahamed: [One more old answer](http://stackoverflow.com/a/15521572/315935) use another options. It can be that you can just add `ajaxGridOptions: { crossDomain: true }` option of jqGrid to solve the problem. I don't know any common solution. – Oleg Mar 12 '15 at 06:21
  • `ajaxGridOptions: { crossDomain: true }` not solved my problem. I write `$.support.cors = true;` at top of jqgrid codes and worked. – hahamed Mar 12 '15 at 10:21
  • 1
    @hahamed: OK, I'm glad to here it. What I mean in my previous comments, that you have probably **pure cors problem** and you should make experiments with jQuery options. The solution can depend on many factors which you don't posted and which can't be solved without having the working (or not full working) demo which reproduces the problem. Even the version of jQuery which you use could be important. It any way it's good that you've found the solution. – Oleg Mar 12 '15 at 10:33