1. #1
    Ext User
    Join Date
    Mar 2007
    Posts
    176
    Vote Rating
    0
    zquirm is on a distinguished road

      0  

    Default [2.x] response empty with file upload Ext.Ajax.request

    [2.x] response empty with file upload Ext.Ajax.request


    I'm using Ext.Ajax.request to submit a file upload form to work with the Scribd API to upload a document.

    The upload works fine, but the response object is returning empty:

    Code:
        {
             argument: undefined,
             responseText: "",
             responseXML: undefined
        }
    Using both Firebug and Safari's developer console, I think the problem is that for some reason the "document" in the iframe used to submit the form is undefined.

    When I remove the "x-hidden" class from the iframe, Scribd's return XML is there:

    Code:
        <rsp stat="ok">
          <doc_id>123456</doc_id>
          <access_key>key-rvfa2c82sq5bf9q8t6v</access_key>
          <secret_password>2jzwhplozu43cyqfky1m</secret_password>
        </rsp>
    and it's encoded:

    Code:
        <?xml version="1.0" encoding="UTF-8"?>
    I can't figure out why Ext.Ajax.request can't read the XML in the callback function.

    It's this function in Ext.data.Connection.doFormUpload that's causing the problem:

    Code:
        function cb(){
                var r = {  // bogus response object
                    responseText : '',
                    responseXML : null
                };
    
                r.argument = o ? o.argument : null;
    
                try { //
                    var doc;
                    if(Ext.isIE){
                        doc = frame.contentWindow.document;
                    }else {
                        doc = (frame.contentDocument || window.frames[id].document);
                    }
                    if(doc && doc.body){
                        r.responseText = doc.body.innerHTML;
                    }
                    if(doc && doc.XMLDocument){
                        r.responseXML = doc.XMLDocument;
                    }else {
                        r.responseXML = doc;
                    }
                }
                catch(e) {
                    // ignore
                }
    
                Ext.EventManager.removeListener(frame, 'load', cb, this);
    
                this.fireEvent("requestcomplete", this, r, o);
    
                Ext.callback(o.success, o.scope, [r, o]);
                Ext.callback(o.callback, o.scope, [o, true, r]);
    
                setTimeout(function(){Ext.removeNode(frame);}, 100);
            }
    Thoughts?

  2. #2
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,538
    Vote Rating
    380
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    Do you use standard Ext way to upload the file or you have your own routine? I'm asking, because Ext uses hidden iframe with form to upload files, Ajax cannot be used.

    You can also take a look at http://filetree.extjs.eu FileUploader class.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid Search Plugin, ExtJS 5 Complex Data Binding using MVVM


  3. #3
    Ext User
    Join Date
    Mar 2007
    Posts
    176
    Vote Rating
    0
    zquirm is on a distinguished road

      0  

    Default


    I'm using Ext's way (Ext.Ajax.request with isUpload set to true). When I remove the "x-hidden" class from the iframe, the XML response is there, so the upload is happening, but the Ajax request response returns empty.

  4. #4
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,538
    Vote Rating
    380
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    Do you return header "Content-Type: text/html; charset=utf8"? Is the body of response {"success":true}?
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid Search Plugin, ExtJS 5 Complex Data Binding using MVVM


  5. #5
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,359
    Vote Rating
    128
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    zquirm -

    This is a bug in Ext 2.2.1 and has been fixed in SVN. Look for it to be resolved in the next release of Ext 2.x. (2.2.2).
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  6. #6
    Ext User
    Join Date
    Mar 2007
    Posts
    176
    Vote Rating
    0
    zquirm is on a distinguished road

      0  

    Default


    Aaron, are there specific files I can copy from the SVN to make this work now? I tried copying the code from Ext.data.Connection to override what's currently there, and I'm still getting an empty response.

  7. #7
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,359
    Vote Rating
    128
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    Update src/widgets/form/Action.js
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  8. #8
    Ext User
    Join Date
    Mar 2007
    Posts
    176
    Vote Rating
    0
    zquirm is on a distinguished road

      0  

    Default


    I'm still getting an undefined response.

    Aaron, looking at this "bug fix" from the forum thread you attached, it looks like this function has been changed in Ext.form.Action:

    Code:
    processResponse : function(response){
            this.response = response;
            if(!response.responseText &&!response.responseXML){
                return true;
            }
            this.result = this.handleResponse(response);
            return this.result;
        }
    This just seems to stop any error reading from going on.

    The problem I'm having is that the "response" argument of this function is returning an object with responseText as empty and responseXML as undefined.

    Which takes me back to the cb() function in Ext.data.Connection.doFormUpload, written out in the first post above, which is telling me that frame.contentDocument and window.frames[id].document do not exist.

    I'm using the Scribd API to upload a document, which is working (the document does upload), and this is the iframe's response:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <rsp stat="ok">
      <doc_id>15345909</doc_id>
      <access_key>key-xxxxxxxxxxxxxxxxxxxxx</access_key>
    </rsp>
    Why can't Ext.data.Connection.doFormUpload read the document?

  9. #9
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,538
    Vote Rating
    380
    jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future jsakalos has a brilliant future

      0  

    Default


    You could step into callback function to see what's happening. From Ext.data.Connection:
    PHP Code:
    function cb(){
                var 
    = {  // bogus response object
                    
    responseText '',
                    
    responseXML null
                
    };

                
    r.argument o.argument null;

                try { 
    //
                    
    var doc;
                    if(
    Ext.isIE){
                        
    doc frame.contentWindow.document;
                    }else {
                        
    doc = (frame.contentDocument || window.frames[id].document);
                    }
                    if(
    doc && doc.body){
                        
    r.responseText doc.body.innerHTML;
                    }
                    if(
    doc && doc.XMLDocument){
                        
    r.responseXML doc.XMLDocument;
                    }else {
                        
    r.responseXML doc;
                    }
                }
                catch(
    e) {
                    
    // ignore
                
    }

                
    Ext.EventManager.removeListener(frame'load'cbthis);

                
    this.fireEvent("requestcomplete"thisro);

                
    Ext.callback(o.successo.scope, [ro]);
                
    Ext.callback(o.callbacko.scope, [otruer]);

                
    setTimeout(function(){Ext.removeNode(frame);}, 100);
            } 
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid Search Plugin, ExtJS 5 Complex Data Binding using MVVM


  10. #10
    Ext User
    Join Date
    Mar 2007
    Posts
    176
    Vote Rating
    0
    zquirm is on a distinguished road

      0  

    Default


    I have.

    Code:
    doc = (frame.contentDocument || window.frames[id].document);
    doc is undefined in both Firefox and Safari.