PDA

View Full Version : FileUpload response in ASP



rabadal
17 Aug 2009, 1:51 AM
I am trying to upload a file to the server.
The file upload correctly, but I have a bug in "success."
What should be the response from the server in ASP?

Thnaks.

moegal
17 Aug 2009, 3:48 AM
Have you tried?

<%
Response.Write("{success: true}")
%>

Marty

rabadal
17 Aug 2009, 4:03 AM
Thanks Marty,

Yes, I tried

This is the code:

buttons: [{
text: 'Enviar',
handler: function(){
if(fp.getForm().isValid()){
fp.getForm().submit({
url: 'subir.asp',
waitMsg: 'Uploading ...',
success: function(fp, o){
msg('Envio', 'Fichero enviado al servidor');
}
});
}
}
},{
text: 'Reset',
handler: function(){
fp.getForm().reset();
}
}]
});


IE error :
It was hoped an object

Condor
17 Aug 2009, 4:06 AM
Did you read the 'File uploads' section (http://extjs.com/deploy/dev/docs/?class=Ext.form.BasicForm) in the BasicForm API docs?

rabadal
17 Aug 2009, 4:21 AM
response in my ASP file es:

Response.ContentType = "text/html"
response.write("{success: true}")


Is correct ????

Thanks,

Condor
17 Aug 2009, 4:31 AM
I assume you meant 'response' (small r)?

Yes, that seems correct. Can you try adding a failure method and check the failureType?

Animal
17 Aug 2009, 4:38 AM
I'm beginning to think that the file load listener on the IFRAME that receives the response needs to fire an event through the Ext.data.Connection object to which users can add listeners to that they can see, test and manipulate the DOM document created in the IFRAME before the machinery attempts to "scrape" JSON from it.

Animal
17 Aug 2009, 4:42 AM
Unfortunately, due to the controversial "privatization" of methods in Ext.data.Connection, you can't override doFormUpload, but I suggest this:



function doFormUpload(o, ps, url){
var id = Ext.id(),
doc = document,
frame = doc.createElement('iframe'),
form = Ext.getDom(o.form),
hiddens = [],
hd,
encoding = 'multipart/form-data',
buf = {
target: form.target,
method: form.method,
encoding: form.encoding,
enctype: form.enctype,
action: form.action
};

Ext.apply(frame, {
id: id,
name: id,
className: 'x-hidden',
src: Ext.SSL_SECURE_URL // for IE
});
doc.body.appendChild(frame);

// This is required so that IE doesn't pop the response up in a new window.
if(Ext.isIE){
document.frames[id].name = id;
}

Ext.apply(form, {
target: id,
method: POST,
enctype: encoding,
encoding: encoding,
action: url || buf.action
});

// add dynamic params
ps = Ext.urlDecode(ps, false);
for(var k in ps){
if(ps.hasOwnProperty(k)){
hd = doc.createElement('input');
hd.type = 'hidden';
hd.value = ps[hd.name = k];
form.appendChild(hd);
hiddens.push(hd);
}
}

function cb(){
var me = this,
// bogus response object
r = {responseText : '',
responseXML : null,
argument : o.argument},
doc,
firstChild;

try{
doc = frame.contentWindow.document || frame.contentDocument || WINDOW.frames[id].document;
this.fireEvent("uploadresponse", doc);
if(doc){
if(doc.body){
if(/textarea/i.test((firstChild = doc.body.firstChild || {}).tagName)){ // json response wrapped in textarea
r.responseText = firstChild.value;
}else{
r.responseText = doc.body.innerHTML;
}
}
//in IE the document may still have a body even if returns XML.
r.responseXML = doc.XMLDocument || doc;
}
}
catch(e) {}

Ext.EventManager.removeListener(frame, LOAD, cb, me);

me.fireEvent(REQUESTCOMPLETE, me, r, o);

function runCallback(fn, scope, args){
if(Ext.isFunction(fn)){
fn.apply(scope, args);
}
}

runCallback(o.success, o.scope, [r, o]);
runCallback(o.callback, o.scope, [o, true, r]);

if(!me.debugUploads){
setTimeout(function(){Ext.removeNode(frame);}, 100);
}
}

Ext.EventManager.on(frame, LOAD, cb, this);
form.submit();

Ext.apply(form, buf);
Ext.each(hiddens, function(h) {
Ext.removeNode(h);
});
}

rabadal
17 Aug 2009, 5:53 AM
Firebug reported de net error:

msg is not defined

what is this ???

rabadal
17 Aug 2009, 6:00 AM
Change msg for Ext.Msg.alert and work fine !!!!!!!!!!!

Thanks.