jQuery-File-Upload icon indicating copy to clipboard operation
jQuery-File-Upload copied to clipboard

data.result undefined when using iFrame-Transport

Open Coma2nd opened this issue 15 years ago • 12 comments

Hey there,

when using the iFrame-Transport-Method (either when using Opera or IE or when forcing Safari or Chrome to use it) my data.result is always in the done-callback undefined.

The server response is a valid JSON-String with content-type text/html: {"upload":{"file":{"url":"/uploads/upload/b5273450-ec22-012e-9f83-549a20f9dbf0/C3_5-T_rer_6_8_2011.pdf"},"uuid":"b5273450-ec22-012e-9f83-549a20f9dbf0","pages":1,"lines":1,"words":0,"chars":1,"source_locale_id":null,"sector":null,"mime":null,"filename":"C3_5-T_rer_6_8_2011.pdf","excerpt":"\n"}}

The frontend is the basic upload-plugin.

Can you help me out, i'm completely out of ideas.

Thanks in advance

Coma2nd avatar Nov 08 '11 10:11 Coma2nd

Are your upload form and the target server on the same domain? Did you set the dataType to "json"?

blueimp avatar Nov 08 '11 10:11 blueimp

Hi,

yes they are on the same domain (localhost for testing) and i've set the dataType to json:

$('#file').fileupload({ dataType: 'json', url: '/de/uploads', done: function (e, data) { documentUploader.addDocument(data.result.resource.upload.filename); }, error: function() {

        },
        start: function() {
          document.getElementById("upload-block").className = 'content-block isLoading';
        }
      });

I seriously have no clue...

Thanks again.

Coma2nd avatar Nov 08 '11 10:11 Coma2nd

Well, you could start debugging by adding

console.log(iframe.contents());

after this line: https://github.com/blueimp/jQuery-File-Upload/blob/master/jquery.iframe-transport.js#L47

blueimp avatar Nov 08 '11 10:11 blueimp

The contents is a HTMLDocument:

Object [HTMLDocument]

If you expand it in Operas console you can access all of it's attributes (URL, activeElement, alinkColor, and so on). In Safaris console you can't access these attributes, but you can see the actual content of the document ... with the correct JSON-String.

Coma2nd avatar Nov 08 '11 11:11 Coma2nd

Try

console.log($.parseJSON(iframe.contents()));

blueimp avatar Nov 08 '11 11:11 blueimp

That gives me 'null'

Thanks again for your help!

Coma2nd avatar Nov 08 '11 11:11 Coma2nd

The problem occurs with new jquery version: 1.7

Bonias avatar Nov 08 '11 16:11 Bonias

Thanks Bonias, I can confirm that with jQuery 1.7, the iframe transport returns an empty response when converting from iframe to text, json or script.

This is probably due to a changed behavior of the .text() method in jQuery 1.7 that is used by the iframe transport converters. Seems it doesn't return anything when called directly on a collection with iframe content documents.

Calling .text() on the body of the iframe content document seems to fix the problem, so I will release an update soon.

blueimp avatar Nov 08 '11 16:11 blueimp

I've submitted an issue to the jQuery bug tracker: http://bugs.jquery.com/ticket/10724

But I've also released an updated version of the iframe transport plugin that should fix this issue.

blueimp avatar Nov 08 '11 18:11 blueimp

I confirm that new version fix the issue. Thanks!

mwysinski avatar Nov 20 '11 11:11 mwysinski

Hi, I am facing the issues with json response undefined with jquery file upload why.?

alert(data.Value); is undefined.

Json response using this way

                return this.Request.CreateResponse(
                            HttpStatusCode.OK,
                            new
                            {
                                Value = UiFileName
                            });

please help me on it asap.

egards

dotnetexpert86 avatar Aug 21 '13 19:08 dotnetexpert86

I had the same issue and I got the clues from below links: (I m using iframe transport for <= IE9, and same domain uploads)

http://stackoverflow.com/a/151404/340290 (this link helped me to know my exact issue) http://stackoverflow.com/questions/1886547

My final understandings:

  • should set dataType: 'json' in the request
  • server should return response in test/html (as iframe requests with Accept: text/html... header and if different response is received, it opens a download window)
  • server should return success (ex: 200) response always (otherwise, IE redirects the iframe response to, for example, res://ieframe.dll/http_500.htm (as described in the above 1st SO.com link))

manikantag avatar Sep 21 '13 10:09 manikantag