nix86
nix86

Reputation: 3037

I can't perform a REST request with Sencha

I want to perform a rest request with sencha ext js. Threfore I created a model and a store with a proxy. Then I invoked the load function of the store. The problem is that after the invocation the store is still empty. I know this because I debugged it. This is the code:

var myModel = Ext.create('Ext.data.Model', {
    fields: [
        { name: 'name' },
        { name: 'age' }
    ]
});

var myStore = Ext.create('Ext.data.Store', {
    model: myModel,
    proxy: {
        type: 'rest',
        url: 'http://localhost:8080/blablabla',
    }
});

myStore.load();

The url 'http://localhost:8080/blablabla' is correct because when I type it in the browser I get the json list of users with the "name" and "age" fields. So the server works.

Here is an example of json that I should get:

[ {
  "id" : 1,
  "name" : "john",
  "age": 40
}, {
  "id" : 2,
  "name" : "jack",
  "age": 30
} ]

Upvotes: 1

Views: 347

Answers (1)

nix86
nix86

Reputation: 3037

My Sencha code was correct. The problem was CORS not enabled. So I resolved by adding @CrossOrigin above my server method.

@CrossOrigin
@RequestMapping
public List<Thing> getThings() {
    ...
    return myListOfThings;
}

@CrossOrigin did the trick.

Upvotes: 0

Related Questions