-
14 Jan 2013 3:33 PM #1
Answered: Can't set Store Proxy method to POST
Answered: Can't set Store Proxy method to POST
I am having trouble with trying to set the method to POST for a store proxy. It seems to default to GET and I can't find the proper place to set the method in the documentation. When I run this from the console as so:
I can see that the request is sent using the GET method.Code:var s = Ext.getStore('venuesStore'); s.load();
Here's my code:
Code:Ext.define('EventsTest.store.Venues', { extend: 'Ext.data.Store', requires: [ 'Ext.data.proxy.JsonP', ], config: { storeId: 'venuesStore', model: 'EventsTest.model.Venue', proxy: { type: 'jsonp', url: 'http://app.onetouchrecycle.ca/index.php/api/get_listings', callbackKey: 'dataReceived', //method: 'POST', actionMethods: { read: 'POST' }, extraParams: { latitude: 45.250157, longitude: -75.800257, radius: 5000 } } }, dataReceived: function(d) { console.log(d); } });
-
Best Answer Posted by talwinder
You can't use JsonP to send a POST request: stating that you are using JsonP, automatically overrides any method type to GET b/c that is the only method it supports.
Read this http://stackoverflow.com/questions/2...-data-to-jsonp
I'm guessing you are using JsonP to avoid getting the Cross-site scripting error. If you really need to use the POST method for your request, I suggest you use a server-side language like PHP to act as a middle man to complete your requests and allow your client side(Sencha) to use the server-side to by changing the access control, read the following link on how to do that:
http://stackoverflow.com/questions/1...l-allow-origin
But in keep in mind that this method isn't very secure, at the very least, I would make use of some random string URL that isn't easy to guess and maybe pass security tokens etc with each request from your Sencha App as well and check them on your server-side to make sure that only 'legitimate' requests are served.
Let me know if you any questions regarding this method. I probably missed a few details.
-
14 Jan 2013 4:21 PM #2
JsonP doesn't support POST, only GET
JsonP doesn't support POST, only GET
You can't use JsonP to send a POST request: stating that you are using JsonP, automatically overrides any method type to GET b/c that is the only method it supports.
Read this http://stackoverflow.com/questions/2...-data-to-jsonp
I'm guessing you are using JsonP to avoid getting the Cross-site scripting error. If you really need to use the POST method for your request, I suggest you use a server-side language like PHP to act as a middle man to complete your requests and allow your client side(Sencha) to use the server-side to by changing the access control, read the following link on how to do that:
http://stackoverflow.com/questions/1...l-allow-origin
But in keep in mind that this method isn't very secure, at the very least, I would make use of some random string URL that isn't easy to guess and maybe pass security tokens etc with each request from your Sencha App as well and check them on your server-side to make sure that only 'legitimate' requests are served.
Let me know if you any questions regarding this method. I probably missed a few details.


Reply With Quote