-
24 Sep 2010 6:48 AM #1
Add parameters to Ajax proxy
Add parameters to Ajax proxy
How do you add parameters to an Ajax store?
I am bypassing the cross domain policy by using a php proxy on my server. I am trying to send a few needed parameters to the php page and I expect the response to be xml.
But how do I send certain parameters to the php page on the server?
PHP Code:var orderStore = new Ext.data.Store({
model: 'order',
url: varxml,
proxy: {
type:'ajax',
id: 'data',
url: 'proxytest.php',
method: "POST",
params:{action: 'askorderlist',
question: 'uborderlist',
value: '2010-08-01',
user: 'username',
password: 'password'
},
reader: {
type: 'xml',
record: 'order'
}
},
autoload: true,
});
-
25 Sep 2010 5:13 AM #2
Just append the parameter to the url:
Code:var orderStore = new Ext.data.Store({ model: 'order', url: varxml, proxy: { type:'ajax', id: 'data', url: 'proxytest.php?username=dummy&age=' + somevar, method: "POST", params:{action: 'askorderlist', question: 'uborderlist', value: '2010-08-01', user: 'username', password: 'password' }, reader: { type: 'xml', record: 'order' } }, autoload: true, });
-
26 Sep 2010 10:05 PM #3
Isn't that a 'GET'? And if so, isn't there a limit to the number of characters you can append to the url?
What if I want to use a 'POST'?
-
26 Sep 2010 10:25 PM #4
By default all read operations will be a get. You can override it for a single instance by using:Code:Ext.setup({ onReady: function(){ Ext.regModel('Foo', { fields: ['a'] }); new Ext.data.Store({ autoLoad: true, model: 'Foo', proxy: { url: 'data.asp', type: 'ajax', extraParams: { foo: 'bar' } } }); } });
Or globally:Code:// create store myStore.proxy.actionMethods.read = 'POST'; myStore.load();
Code:Ext.apply(Ext.data.AjaxProxy.prototype.actionMethods, { read: 'POST' }); // create storeEvan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
26 Sep 2010 10:36 PM #5
Thanks Evant for your quick response. In your example the extraParams you pass to the proxy also are present in the model, is this a necessity?
I am still getting errors. Is there a 'success' and 'failure' parameter for stores or readers, like with an Ext.Ajax.request?
PHP Code:XHR finished loading: "http://localhost/proxytest.php?_dc=1285569086510".ext-touch-debug.js:7732
Uncaught #<an Object>
getResponseData ext-touch-debug.js:7732
readext-touch-debug.js:7235
(anonymous function)ext-touch-debug.js:6620
onCompleteext-touch-debug.js:14577
onStateChangeext-touch-debug.js:14524
(anonymous function)ext-touch-debug.js:2618
-
26 Sep 2010 10:38 PM #6
No, I just happened to use the same name for the model and the property, they are in no way related.
As for the other one, it sounds like you're sending back malformed data.Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
26 Sep 2010 10:41 PM #7
The response should be something like : <?xml version="1.0" encoding="UTF-8"?><orderlist><order><orderid>2005048</orderid></order><order><orderid>3000359</orderid></order><order><orderid>2007062</orderid></order><order><orderid>2007118</orderid></order><order><orderid>3000362</orderid></order><order><orderid>2007134</orderid></order><order><orderid>2007135</orderid></order><order><orderid>2007142</orderid></order><order><orderid>3000367</orderid></order><order><orderid>2007178</orderid></order></orderlist>
Could it be the header (<?xml version="1.0" encoding="UTF-8"?>) that is causing the problem?
With Chrome dev tools, when I click on "http://localhost/proxytest.php?_dc=1285569086510", it displays the correct output.
-
26 Sep 2010 11:11 PM #8
And my model is
Anyone an idea what I am doing wrong?PHP Code:Ext.regModel('order', {
fields : [ {
name : 'orderid',
type : 'integer'
}]
});
-
27 Sep 2010 12:37 AM #9
Oke, I made sure that the server returns text/xml, by adding 'header("Content-Type: text/xml");' to the php document. So now I don't get any errors, but the store still doesn't get filled.
-
27 Sep 2010 12:52 AM #10
Similar Threads
-
Ajax.request VS Store proxy
By merry andrew in forum Sencha Touch 1.x: DiscussionReplies: 1Last Post: 23 Aug 2010, 4:09 PM -
Ajax Proxy/Json Store
By eldiego34 in forum Sencha Touch 1.x: DiscussionReplies: 2Last Post: 19 Aug 2010, 4:59 AM -
[FIXED-94] Server Proxy doesn't apply sorters, limit, start to the request Parameters
By crp_spaeth in forum Sencha Touch 1.x: BugsReplies: 2Last Post: 29 Jun 2010, 2:46 PM -
Problem with proxy ajax call
By mysticav in forum Ext 2.x: Help & DiscussionReplies: 5Last Post: 4 Dec 2008, 12:10 PM -
is data proxy is the same as ajax?
By ratno in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 24 Nov 2008, 8:35 AM


Reply With Quote