PDA

View Full Version : xmlstore GET requests?



adjohn
13 Jul 2010, 10:25 PM
Hi, I admit I am very new to ExtJS so this may be a newb question:

I created a basic xmlstore in designer to pull data from a REST API we have. In Designer, when I load the data, it works fine and retrieves the results and displays them in a grid. When I export the code, and run it in the browser (Chrome, and Firefox) it does not appear to work. I get a 200 OK from the server, but no xml response.

I checked firebug, and it looks like the problem may be that the request type is OPTIONS instead of a GET. I don't think the API supports OPTIONS. When I enter the same url into the web browser I get a proper xml response.

Is there some way to change the request type to at GET? Or, what would the designer be doing differently?

The store code is as follows:

bucketREST = Ext.extend(Ext.data.XmlStore, {
constructor: function(cfg) {
cfg = cfg || {};
bucketREST.superclass.constructor.call(this, Ext.apply({
storeId: 'bucketREST',
url: 'http://foo.com:9999/fooapi/',
autoLoad: true,
record: 'Bucket',
autoSave: false,
fields: [
{
name: 'Name'
}
]
}, cfg));
}
});
new bucketREST();

jarrednicholls
14 Jul 2010, 6:37 AM
Hi adjohn,

When you see an "OPTIONS" request going out, it means that the browser is checking the server to see if it is allowed to do a cross-domain request. Generally, this is *not* allowed in browsers because it is a security risk. You are loading your project from either a local address or directly from the files, and trying to do an Ajax request to a domain that doesn't match the domain from where you loaded the project. Later browsers like Firefox support the OPTIONS call to do a ping asking "hey, external domain, will you accept this Ajax request from this external domain?" But some browsers simply reject the request.

In the Designer, we set a flag in our browser shell to allow external domain requests, so that's why you see it working fine in the Designer but not fine in your browser. You need to either run the project from the same domain where you are loading the data, or you need to manually change your DataProxy that the store uses to something that is cross-domain compatible, such as a ScriptTagProxy (http://www.sencha.com/deploy/dev/docs/?class=Ext.data.ScriptTagProxy), which is not configurable through the Designer interface at this time but can be setup in your implementation code. By default, the store will have an HttpProxy configured, which does a standard Ajax/XHR request.

Hope that helps!