0

I have the following code to retrieve the a JSON structure from another domain and display it on the page.

However, nothing appears and I get the this error in the console:

Uncaught SyntaxError: Unexpected token : People.json:2

I've passed my JSON into a JSON validator and it came back as valid.

Here is my code:

    Ext.define("Person", {
        extend: "Ext.data.Model",
        config: {
            fields: [
                { name: 'Id', type: 'int'},
                { name: 'Name', type: 'string'},
                { name: 'Email', type: 'string'}
            ]
        }
    });

    var myStore = Ext.create("Ext.data.Store", {
        model: "Person",
        proxy: {
            type: "jsonp",
            url: 'http://example.com/People.json',
            reader: {
                type: "json",
                rootProperty: "Person"
            }
        },
        autoLoad: true
    });

    Ext.create("Ext.List", {
        fullscreen: true,
        store: myStore,
        itemTpl: "{Name}, {Id}"
    });

Here are the contents of my JSON file:

{
    "Person": [
        {
            "Id": 0,
            "Name": "Robert Lara",
            "Email": "rolara@example.com"
        },
        {
            "Id": 1,
            "Name": "Tom Hicks",
            "Email": "tohicks@example.com"
        }
    ]
}
shrewdbeans
  • 11,971
  • 23
  • 69
  • 115

1 Answers1

0

JSONP is not literally transporting JSON, it expects http://example.com/People.json to be Javascript file calling a callback function.

You have taken care of the client side part of JSONP using Sencha, but you have to prepare server side to work with it.

The Sencha docs on JSONP have a paragraph and some code examples under the title Implementing on the server side:

Also this StackOverflow question explains what JSONP is all about.

Community
  • 1
  • 1
MDerks
  • 123
  • 5
  • According the the Sencha documentation, this is taken care of for you: http://docs-origin.sencha.com/touch/2.3.1/#!/api/Ext.data.proxy.JsonP - am I missing something in my code? – shrewdbeans Jan 07 '14 at 17:26
  • 1
    Sencha take care of client side part of JSONP, you have to prepare server side to work with it. Check out paragraph **Implementing on the server side** in doc from your link – MDerks Jan 08 '14 at 09:05