PDA

View Full Version : How to force "post" method in Ajax.request



kmchen13
3 Nov 2011, 2:37 AM
Hi everybody,

I'm newbie to Extjs and can't make POST ajax requests work correctly. Whatever I try, like:


Ext.Ajax.request({
method: 'POST',
params: {
x: csv_data,
},
success: function(result, request){
},
failure: function(result, request){
},

requests are sent with GET method and I get the apache error "request failed: URI too long (longer than 8190)" if my csv_data is too long.

Any help appreciated.

kmchen13
3 Nov 2011, 3:33 AM
I see in Ext.data.Connection.Override.js :

if (o.scriptTag || this.scriptTag || Ext.lib.Ajax.isCrossDomain(url)) { this.transId = this.scriptRequest(method, url, cb, p, o);

} else {

this.transId = Ext.lib.Ajax.request(method, url, cb, p, o);


and scriptRequest overrides any method to GET:

scriptRequest : function(method, url, cb, data, options) {
...
url += (url.indexOf("?") != -1 ? "&" : "?") + data + String.format("&{0}={1}", options.callbackParam || this.callbackParam || 'callback', trans.cb);


Is this normal? How to transmit POST data in crossdomain situations?

mitchellsimoens
3 Nov 2011, 5:50 AM
The only cross domain functionality will use GET

kmchen13
4 Nov 2011, 2:48 AM
I absolutely need POST method. Will it work if I change code


if (o.scriptTag || this.scriptTag || Ext.lib.Ajax.isCrossDomain(url)) { this.transId = this.scriptRequest(method, url, cb, p, o); } else { this.transId = Ext.lib.Ajax.request(method, url, cb, p, o);
with

this.transId = Ext.lib.Ajax.request(method, url, cb, p, o);
?

mitchellsimoens
4 Nov 2011, 4:02 AM
Ext.Ajax.request({
method : 'POST',
url : 'something',
params : {}
});

Will work but only same domain... Any cross-domain will not use POST

kmchen13
4 Nov 2011, 10:15 AM
You are telling me that there is no way to send a POST Ajax request upon cross domains ?!
Is there a reason to that ?

mitchellsimoens
4 Nov 2011, 10:21 AM
You are telling me that there is no way to send a POST Ajax request upon cross domains ?!
Is there a reason to that ?

It's browser security not to allow cross-origin Ajax requests. The way it is done is adding a script tag with the url you are sending the request as the src which the browser will only send as GET.

You may want to look into CORS to see if you can get that running.