0
votes

I don't understand how to get information from another domain in Sencha Touch. I want to fill my store with data retrieved from a javascript, that got the information from another webservice.

For a test, I wrote following code in simpleTest.js:

function hello(){
"test":[{ "text": "hello"}];
}

And the store looks like this:

Ext.define("AccessibleMap.store.Teststore", {
    extend: "Ext.data.Store",
    config: {
        model: "AccessibleMap.model.Testmodel",
        autoLoad: true,
        proxy:{
            type: 'jsonp',
            url: 'http://test.accessiblemap.square7.ch/live%20access/scripts/simpleTest.js',
            reader:{
                type : 'json',
                rootProperty : 'test'
            }
        }
    }
});

The error message shows, that it can't find the page.

Uncaught SyntaxError: Unexpected token :            simpleTest.js:2  

The problem seems to be the callback. How can I fix this?

How can I create a callback in javascript? Do I need to stringify the returning string to with json?

1
Your server is responding with 404. The problem is the URL you are requesting does not exist. Fix that first...Macy Abbey
Ok, I forgot that the script is in a subfile sorry. But there is still an error.Pilzli

1 Answers

0
votes

You need to tell the JavaScript to output the json, you cannot just write it in. Your code should be:

function hello(){
    document.write('{"test":[{ "text": "hello"}]}');
}

You were also missing braces around your json {}

Some other things to note as well when you start actually writing your proper callbacks. You can use the Ext.JSON class to encode / decode json (Ext.JSON.encode / Ext.JSON.decode). I personally use a PHP backend and just use the native PHP functions to spit out my json.