1

Trying to use sencha proxy - but no luck - I get the error - Uncaught SyntaxError: Unexpected token :

    Ext.define('The.store.Login', {
        extend: 'Ext.data.Store',
        config: {
            model: 'The.model.Login',
            proxy: {
                type: 'jsonp',
                url: 'THE_URL_THAT_RETURNS_JSON',
                headers: {
                        'Access-Control-Allow-Origin': '*',
                        'Content-Type': 'application/json',
                        'Authorization': 'THE_AUTH_BASE64_ENCODED_KEY'
                },
                reader: {
                    type: 'json',
                    rootProperty: 'd'
                }
            },
            autoLoad: false

        }
    });

This is my sencha code

And the json that comes back is -

    {
    "d" : [
    {
    "__metadata": {
    "uri": "States", "type": "State"
    }, "CountryCodeString": "USA", "StateCode": "AA", "ActiveFlag": true, "StateDescription": "Americas"
    }, {
    "__metadata": {
    "uri": "States", "type": "State"
    }, "CountryCodeString": "CAN", "StateCode": "AB", "ActiveFlag": true, "StateDescription": "Alberta"
    }, {
    "__metadata": {
    "uri": "States", "type": "State"
    }, "CountryCodeString": "BRA", "StateCode": "AC", "ActiveFlag": true, "StateDescription": "AC"
    }, {
    "__metadata": {
    "uri": "States", "type": "State"
    }, "CountryCodeString": "AUS", "StateCode": "ACT", "ActiveFlag": true, "StateDescription": "ACT"
    }, { .....
vivianaranha
  • 2,781
  • 6
  • 33
  • 47

2 Answers2

1

If you are using JsonP then a callback is required from the server. I.E.

callback4587({"json":"here"})

The callback will be sent as a parameter automatically by ExtJS framework and the server will need to respond with the same callback.

If you use Ajax request the callback will not be required. However, you will need to setup cross origin access in server configuration.

weeksdev
  • 4,265
  • 21
  • 36
  • 1
    I do not have access to teh server - all I can change is the Sencha code - What would you Suggest and Thanks a million for teh reply – vivianaranha Dec 30 '13 at 20:00
  • 1
    I'm not positive there is a way around having the `callback` because it would be difficult to tell which response was for which request since JsonP uses `script tags` on `html element`. Here is a link to a great [explanation](http://stackoverflow.com/questions/5943630/basic-example-of-using-ajax-with-jsonp) of `JsonP` and `callback` – weeksdev Dec 30 '13 at 20:20
  • Is there any other alternate method - maybe ajax or rest - I can do anythign with the frontend - but dotn have access to server – vivianaranha Dec 31 '13 at 17:11
  • You may be able to use `form.submit()` to a new page, i don't believe there would be access-origin constraints in that instance, however using `form.submit()` within an `iframe` would still cause issues in some browsers i believe. `Ajax` will not work without proper setup on the server for access-origin. – weeksdev Dec 31 '13 at 17:18
1

Change your proxy type to ajax.

Jsonp is required for retrieving data from a server in a different domain.

tom redfern
  • 30,562
  • 14
  • 91
  • 126
Krishna
  • 5,194
  • 2
  • 28
  • 33