wang
11 Jun 2008, 11:31 PM
Hey guys,
I found a problem while submitting a form with a file using AJAX.
The code is just like that.
Ext.Ajax.request({
url: url,
form: editCateForm.el.dom,
method: "PUT",
isUpload: true,
headers: Constants.DEFAULT_REQUEST_HEADERS,
callback: CateGridManager.submitEditCateFinished
});
The problem is that the method is always "POST" when isUpload is true, in spite of my config.
Then I read the source code of connection.js.
doFormUpload : function(o, ps, url){
var id = Ext.id();
var frame = document.createElement('iframe');
frame.id = id;
frame.name = id;
frame.className = 'x-hidden';
if(Ext.isIE){
frame.src = Ext.SSL_SECURE_URL;
}
document.body.appendChild(frame);
if(Ext.isIE){
document.frames[id].name = id;
}
var form = Ext.getDom(o.form);
form.target = id;
form.method = 'POST';
form.enctype = form.encoding = 'multipart/form-data';
if(url){
form.action = url;
}
var hiddens, hd;
if(ps){ // add dynamic params
hiddens = [];
ps = Ext.urlDecode(ps, false);
for(var k in ps){
if(ps.hasOwnProperty(k)){
hd = document.createElement('input');
hd.type = 'hidden';
hd.name = k;
hd.value = ps[k];
form.appendChild(hd);
hiddens.push(hd);
}
}
}
...
form.submit();
When it is a file upload, EXT submits in a quite different way. It creates an iframe with a form in it and submits the form, instead of "Ext.lib.Ajax.request". So I wonder why it have to do so? Does it mean that we can not upload a file with the XMLHttpRequest object?
I found a problem while submitting a form with a file using AJAX.
The code is just like that.
Ext.Ajax.request({
url: url,
form: editCateForm.el.dom,
method: "PUT",
isUpload: true,
headers: Constants.DEFAULT_REQUEST_HEADERS,
callback: CateGridManager.submitEditCateFinished
});
The problem is that the method is always "POST" when isUpload is true, in spite of my config.
Then I read the source code of connection.js.
doFormUpload : function(o, ps, url){
var id = Ext.id();
var frame = document.createElement('iframe');
frame.id = id;
frame.name = id;
frame.className = 'x-hidden';
if(Ext.isIE){
frame.src = Ext.SSL_SECURE_URL;
}
document.body.appendChild(frame);
if(Ext.isIE){
document.frames[id].name = id;
}
var form = Ext.getDom(o.form);
form.target = id;
form.method = 'POST';
form.enctype = form.encoding = 'multipart/form-data';
if(url){
form.action = url;
}
var hiddens, hd;
if(ps){ // add dynamic params
hiddens = [];
ps = Ext.urlDecode(ps, false);
for(var k in ps){
if(ps.hasOwnProperty(k)){
hd = document.createElement('input');
hd.type = 'hidden';
hd.name = k;
hd.value = ps[k];
form.appendChild(hd);
hiddens.push(hd);
}
}
}
...
form.submit();
When it is a file upload, EXT submits in a quite different way. It creates an iframe with a form in it and submits the form, instead of "Ext.lib.Ajax.request". So I wonder why it have to do so? Does it mean that we can not upload a file with the XMLHttpRequest object?