0

Using the tutorial given here, I am making an app to fetch json data from a URL and display it. I am using this code to call the URL and parse.

{
                    xtype: 'nestedlist',
                    title: 'Blog',
                    iconCls: 'star',
                    cls: 'blog',
                    displayField: 'title',

                    store: {
                        type: 'tree',

                        fields: ['uuid', 'display'


                        ],

                        root: {
                            leaf: false
                        },

                        proxy: {
                            type: 'scripttag',
                            url: 'http://localhost:8081/openmrs-standalone/ws/rest/v1/location',
                            reader: {
                                type: 'json',
                                rootProperty: 'results'
                            }
                        },

                    },

                },

In the console i am getting response in the form

{
    "results": [
        {
            "uuid": "c0937f0c-1691-11df-97a5-7038c432aabf",
            "display": "Chulaimbo",
            "links": [
                {
                    "uri": "http://localhost:8081/openmrs-standalone/ws/rest/v1/location/c0937f0c-1691-11df-97a5-7038c432aabf",
                    "rel": "self"
                }
            ]
        },
        {
            "uuid": "c0937d4f-1691-11df-97a5-7038c432aabf",
            "display": "Mosoriot Hospital",
            "links": [
                {
                    "uri": "http://localhost:8081/openmrs-standalone/ws/rest/v1/location/c0937d4f-1691-11df-97a5-7038c432aabf",
                    "rel": "self"
                }
            ]
        },
        {
            "uuid": "8d6c993e-c2cc-11de-8d13-0010c6dffd0f",
            "display": "Unknown Location",
            "links": [
                {
                    "uri": "http://localhost:8081/openmrs-standalone/ws/rest/v1/location/8d6c993e-c2cc-11de-8d13-0010c6dffd0f",
                    "rel": "self"
                }
            ]
        }


    ]
}

but its showing an error enter image description here "location" is the name of the service.

Diffy
  • 2,339
  • 3
  • 25
  • 47

2 Answers2

0

The console believes you are trying to execute the JSON as code. So after the first {, it expects instruction. Not data. Try putting parentheses around the entire thing:

{ myfield: 1, anotherfield: 2 } (ERROR)

({ myfield: 1, anotherfield: 2 }) (SUCCESS)

This will resolve the issue.

wizulus
  • 5,653
  • 2
  • 23
  • 40
  • the server respone is not in my hands. I cant change it – Diffy Feb 27 '14 at 19:24
  • How exactly are you using the "server response"? – wizulus Feb 27 '14 at 19:25
  • I have to display any one field say "results" of the response in a list. But i am not able to parse the json – Diffy Feb 27 '14 at 19:26
  • How are you parsing the JSON? eval()? JSON.parse()? – wizulus Feb 27 '14 at 20:56
  • I dont have to parse JSON using JSON.parse() or eval(). I have set 'rootproperty: results' and 'displayfield:display'. So it will parse json and show me the 'display' field of each object – Diffy Feb 28 '14 at 05:41
  • So you parse the JSON by setting rootproperty and displayfield? can you show the syntax of how that is done? – wizulus Feb 28 '14 at 14:55
  • this is how its done in the sencha link that i have provided. http://docs.sencha.com/touch/2.3.1/#!/guide/first_app – Diffy Feb 28 '14 at 17:49
0

I have done it using a different method. I used proxytype 'rest' and run OpenMRS and my application on the same server and port otherwse my instance of OpenMRS wont allow cross-domain calls. The problem in this question was using type as "scripttag" which i still dont know what is the problem with it.Using "rest" resolves it.

Diffy
  • 2,339
  • 3
  • 25
  • 47