andreasnauta
andreasnauta

Reputation: 638

Dojo: DataGrid from a JsonRest Store

I am trying to follow the tutorial here:

http://dojotoolkit.org/documentation/tutorials/1.7/store_driven_grid/

The tutorial writes:

require(["dojo/store/JsonRest"], function(JsonRest){
myStore = new JsonRest({target:"MyData/"});

My MyData.json file is placed in ROOT\MyData. If I run the following code

...
<script>
var myStore, dataStore, grid;
require(["dojo/store/JsonRest"], function(JsonRest){
    myStore = new JsonRest({target:"MyData/"});
});

require(["dojox/grid/DataGrid",
         "dojo/data/ObjectStore",
         "dojo/domReady!"
], function(DataGrid, ObjectStore){
        grid = new DataGrid({
        store: dataStore = ObjectStore({objectStore: myStore}),
        structure: [
            {name:"State Name", field:"name", width: "200px"},
            {name:"Abbreviation", field:"abbreviation", width: "200px"}
        ]
        }, "target-node-id"); // make sure you have a target HTML element with this id
        grid.startup();
});
</script>
...

I get a 404 error on the data if I write "MyData/" and a 416 (Requested Range Not Satisfiable) if I put "MyData/MyData.json".

I know it is something totally stupid, since I can't find anyone have the same problem, but I am unable to see the solution :/

Best regards and thank you for your help!

Andreas

Upvotes: 0

Views: 3175

Answers (1)

Jmsegrev
Jmsegrev

Reputation: 261

Ok so the data you are providing is not enough to determine whats the problem, but 404 is not found.

So:

  1. Make sure you can access the json file via the browser without problems.
  2. If you do, use this url in the {target:"http://URL"}, this should work.
  3. Remember that in the dojo.store.JsonRest target option {target:"relative or absolute"}, if relative path is used, it will look in the path of the executed script.

E.g. If your grid script is in http://localhost/grid/, then the JsonRest will look relative to this path. For a target {target:"MyData.json"} it will look in http://localhost/grid/MyData.json, not finding it, if it where in http://localhost/MyData.json

If you still can't solve this post again!!

Upvotes: 1

Related Questions