genix
12 Jun 2010, 12:20 PM
Hi,
I couldn't find an plugin or sth. like that, which was able to do a file download by sending a POST request.
here is the code:
var Utils = {
download: function(kurvclass, command, data){
if (kurvclass && command) {
if(Ext.query('body iframe#remoteCall').length == 0){
Ext.getBody().appendChild(Ext.DomHelper.createDom({
tag: 'iframe',
id: 'remoteCall',
name: 'remoteCall',
style: {
display: 'none'
}
}));
}
var inputs = '';
// POST params....
var params = {
kurvAction: kurvclass,
kurvMethod: command,
kurvData: Ext.encode(data),
type: 'rpc',
kurvTID: ++Ext.Direct.TID
};
Ext.iterate(params, function(key, value){
inputs += "\n\t" + '<input type="hidden" name="' + key + '" value=\'' + value + '\'>';
});
var el = Ext.DomHelper.createDom({
tag: 'form',
action: Ext.app.REMOTING_API.url,
method: 'POST',
target: 'remoteCall',
html: inputs
})
var form = Ext.getBody().appendChild(el);
form.dom.submit();
form.remove();
};
}
};
so if you now call Utils.download('class','methods',{param1: 'haha}) the function will create an form and submit it in an iframe. The server sends back an file.
I modified the Ext.Direct PHP class so that it can also process Form-POST requests.
I hope you'll like it.
Greets,
genix
P.S. sorry for my bad english
I couldn't find an plugin or sth. like that, which was able to do a file download by sending a POST request.
here is the code:
var Utils = {
download: function(kurvclass, command, data){
if (kurvclass && command) {
if(Ext.query('body iframe#remoteCall').length == 0){
Ext.getBody().appendChild(Ext.DomHelper.createDom({
tag: 'iframe',
id: 'remoteCall',
name: 'remoteCall',
style: {
display: 'none'
}
}));
}
var inputs = '';
// POST params....
var params = {
kurvAction: kurvclass,
kurvMethod: command,
kurvData: Ext.encode(data),
type: 'rpc',
kurvTID: ++Ext.Direct.TID
};
Ext.iterate(params, function(key, value){
inputs += "\n\t" + '<input type="hidden" name="' + key + '" value=\'' + value + '\'>';
});
var el = Ext.DomHelper.createDom({
tag: 'form',
action: Ext.app.REMOTING_API.url,
method: 'POST',
target: 'remoteCall',
html: inputs
})
var form = Ext.getBody().appendChild(el);
form.dom.submit();
form.remove();
};
}
};
so if you now call Utils.download('class','methods',{param1: 'haha}) the function will create an form and submit it in an iframe. The server sends back an file.
I modified the Ext.Direct PHP class so that it can also process Form-POST requests.
I hope you'll like it.
Greets,
genix
P.S. sorry for my bad english