PDA

View Full Version : POST Request with extraParams



m400mail
25 Nov 2011, 4:42 AM
Hello all,

i need a POST Request with additional Parameters because the PHP script answers only by post:



Ext.define('APP01.store.datastore_Users', {
extend: 'Ext.data.Store',
fields: ['name', 'email'],
model: 'APP01.model.Model_User',
autoLoad: true,

proxy: {
type: 'ajax',
url: 'http://xxxxx.de/AWK/AWK_PHP/Server_Data_of_AWK_Demo.php',
actionMethods: {
create : 'POST',
read : 'GET',
update : 'POST',
destroy: 'POST'
},
extraParams: {assid:'test', asearch: '%'},

reader: {
type: 'xml',
root: 'sqllistlist',
record: 'sqllist'
successProperty: 'success'
}
}


});

This creates a GET Request with the Parameter
assid='test '
asearch= '%'

but when i change it to POST

Ext.define('APP01.store.datastore_Users', {
extend: 'Ext.data.Store',
fields: ['name', 'email'],
model: 'APP01.model.Model_User',
autoLoad: true,

proxy: {
type: 'ajax',
url: 'http://xxxxx.de/AWK/AWK_PHP/Server_Data_of_AWK_Demo.php',
actionMethods: {
create : 'POST',
read : 'POST',
update : 'POST',
destroy: 'POST'
},
extraParams: {assid:'test', asearch: '%'},

reader: {
type: 'xml',
root: 'sqllistlist',
record: 'sqllist'
successProperty: 'success'
}
}


});


there are no Parameter
if this right ?:-?

skirtle
25 Nov 2011, 4:47 AM
The parameters will be in the POST body, as they should be. Most web frameworks will allow you to access them just like GET parameters.

If you really want them on the URL then just add them directly to the URL you configure.

m400mail
25 Nov 2011, 5:13 AM
29576
hello,
the Firebug displays with EXTJS the "OPTIONS" text when i submit with the POST request.
normally diplays the GET or POST

tvanzoelen
25 Nov 2011, 5:15 AM
Then you are doing probably a cross-domain request. Set proxy type to jsonp.

skirtle
25 Nov 2011, 5:31 AM
Agreed, looks like a CORS request.

If you need to overcome the same-origin policy you'll either need to use CORS (not supported in all browsers) or JSON-P. Either way the server will need to be changed to support the technique you choose.

One alternative is to proxy the server through your own server so that the same-origin policy isn't an issue.

m400mail
25 Nov 2011, 5:47 AM
Hello,

i have changed the proxy type to jsonp

proxy: {
type: 'jsonp',
url: 'http://xxxxnline.de/AWK/AWK_PHP/Server_Data_of_AWK_Demo.php',
actionMethods: {
create : 'POST',
read : 'POST',
update : 'POST',
destroy: 'POST'
},
extraParams: {assid:'test', asearch: '%', aaction:'loaduserlist'},


but EXT sends the Request as GET

skirtle
25 Nov 2011, 5:57 AM
This is to be expected, JSON-P requests can only be made over GET.

If you need to use a POST request against a server from a different origin then you'll either need to use CORS or proxy the server through your own server.

I suggest you do some Google searching and read up about the same-origin policy, JSON-P and CORS. These are not ExtJS-specific concepts.

tvanzoelen
25 Nov 2011, 5:58 AM
jsonp can only do a get request.

chrisjs
20 Feb 2012, 5:08 AM
Hello,

i have the same problem.

I also have defined a model with proxy, configured urls for READ and UPDATE.
I want to add extraparams with



record.proxy.extraParams = {
'mode': 'ModeUpdate',
'scope': ['account']
};


It is expected that scope is an array, because there could be other data in the request.
Why the extraparams are always added as GET-parameters to the url?