Results 1 to 10 of 35

Thread: <pre>json</pre> in File upload response (FF only)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Ext User
    Join Date
    Apr 2007
    Posts
    26
    Vote Rating
    0
      0  

    Default <pre>json</pre> in File upload response (FF only)

    I'm actually not 100% sure if this is an Ext bug or not, but I'm having problems with the following code (essentially handling a File Upload through a Ext.Window):

    Code:
    // ignore ${auto_var} -- it is part of a code generator
    
    var ${auto_var}_form = new Ext.form.FormPanel({
      frame : true,
      defaultType : 'textfield',
      waitMsgTarget : true,
      bodyStyle : 'padding:5px 5px 0',
      labelAlign : 'left',
      buttonAlign: 'right',
      fileUpload : true,
      enctype : 'multipart/form-data',
      items : [
      {
        fieldLabel : 'Attachment',
        inputType : 'file'
      }
    ]
    });
    
    var ${auto_var}_submit = ${auto_var}_form.addButton({
      text:"Submit",
      handler: function()
      {
        ${auto_var}_form.form.submit({
          url:'upload',
          waitMsg : "Uploading...",
          success: function(f,a){
            console.log(a);
          }
      });
      }
    })
    Console reports:
    Code:
    [Break on this error] (<pre>{success:true}</pre>)
    I know for 100% that I am not returning <pre> tags.

    What is happening, I think, is that because the response happens in an IFRAME (because of File Upload, I presume), Firefox is automatically wrapping the response in a DOM, then the IFRAME content is pulled out and eval'ed.

    My Spring controller simply returns:

    Code:
    res.setHeader("Content-type","text/javascript");
    res.getWriter().write("{success:true}");
    return null;
    I've tried application/json, but this just prompts a File/download dialog.

    The only fix I can think of is edit Ext's decode function to handle the <pre> tags:
    Code:
    this.decode = function(json){
       // check if there are <pre> tags and strip them out.
       return eval("(" + json + ')');
    };
    Any suggestions??

  2. #2
    Ext User
    Join Date
    Apr 2007
    Posts
    17
    Vote Rating
    0
      0  

    Default

    you should modify method 'decode' to get rid of tag '<pre> </pre>'.
    and then everything will work well.
    but i gotta another problem, uploadform works fine in FF, but fails in IE6.0.
    IE cannot submit any request to ther server, and throw some js exception.
    could you give me any clue??

  3. #3
    Sencha User McCornic's Avatar
    Join Date
    Oct 2007
    Posts
    29
    Vote Rating
    0
      0  

    Question

    Any body know if this bug is going to be solve?
    Because I have the same issue <pre>...</pre>.
    And i think it's not clean to get rid of tag '<pre> </pre>'.
    And it doesn't look work on IE6
    Please the Ext team help us.... ;-)

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,607
    Vote Rating
    59
      0  

    Default

    Uploads are done using a form submit which loads an iframe.

    It's expecting an HTML document. It gets the "responseText" by extracting the innerHTML of the document. That's what FF puts there. It wraps plain text responses with <pre> tags.

    There was a long discussion about this with several workaruonds posted, but the dev team have not looked at it.

  5. #5
    Ext User
    Join Date
    Apr 2007
    Posts
    4
    Vote Rating
    0
      0  

    Default

    Has any "official" method of getting around this surfaced yet? I too am facing this (rather annoying) problem.

  6. #6
    Ext User
    Join Date
    Jul 2007
    Location
    Washington, DC
    Posts
    190
    Vote Rating
    0
      0  

    Default

    I do file uploads and I have never had this problem, it is all in the way you return the JSON formatted response, for whatever reason, the method being used her is wrapping it in <pre></pre> tags. If you don't return it with that then there is no problem. It isn't a bug.

  7. #7
    Sencha User Frank's Avatar
    Join Date
    Mar 2007
    Posts
    186
    Vote Rating
    1
      0  

    Default

    Presumably the file uploader thing should be looking at .textContent, not .innerHTML.
    Ext Every Day!
    ajaxjs.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •