3

i have done kendo ui tree with json file

this is working fine if the file is on local machine

here is the code which i am using

<script type="text/javascript" charset=utf-8>
    $(document).ready(function () {
    $.getJSON("/test/test.json", function (data) {
        $("#treeview").kendoTreeView({
            dataSource    : {
                data: data
            },
            dataTextField : "text",
            dataValueField: "id"
        });
    });
   });
</script>

Now i have uploaded this file to the server and i am passing the live

URL in the same code but it is not working code is here

<script type="text/javascript" charset=utf-8>
    $(document).ready(function () {
    $.getJSON("http://eragonsolutions.com/test/test.json", function (data) {
        $("#treeview").kendoTreeView({
            dataSource    : {
                data: data
            },
            dataTextField : "text",
            dataValueField: "id"
        });
    });
   });
</script>

what changes do i need to do???

Thanks in advance

M.I.T.
  • 1,040
  • 2
  • 17
  • 34

2 Answers2

0

Are you running this code, try again..

    var dataSource = new kendo.data.HierarchicalDataSource({
    transport: {
        read: {
            url: "http://eragonsolutions.com/test/test.json",
            dataType: "jsonp"
        }
    } 
});

$("#treeview").kendoTreeView({
    dataSource: dataSource,
    dataTextField: "text",
    dataValueField: "id"
});
bykrkc
  • 13
  • 1
  • 4
0

You can't use $.getJSON to load JSON from another domain; if this is a cross-domain request, you need to use dataType "jsonp" for your $.ajax request and the server has to be able to handle that properly, i.e. it can't simply return the JSON but needs to wrap it with the callback function provided with the request. See this answer for an example.

Community
  • 1
  • 1
Lars Höppner
  • 18,252
  • 2
  • 45
  • 73