Giter Club home page Giter Club logo

Comments (16)

mjquinlan2000 avatar mjquinlan2000 commented on July 26, 2024

It seems that Chrome does some weird things with the iframe component of this directive. If you change line 67 of ng-upload.js to:

    var content = $.parseJSON(iframe.contents().find('body').text());

and change line 73 to:

    if (content != null) { // Fixes a bug in Google Chrome that dispose the iframe before content is ready.

Then it parses the JSON correctly. Also, I had some problems returning JSON to IE (typical) and it turns out that Microsoft has a hard time recognizing application/json as a MIME type, so rendering as text/plain works with this solution as well. Hope that helps.

from ngupload.

twilson63 avatar twilson63 commented on July 26, 2024

Hey @mjquinlan2000,

Yea, the main problem is IE, but I just tried incorporating your changes and it breaks the first example. If your changes can be applied without breaking the examples, I will be happy to incorporate them.

Thanks

Tom

from ngupload.

yesnault avatar yesnault commented on July 26, 2024

This is my fix (I work with JSON only) yesnault@0412f06

but why don't let the user choose between .text() and .html() ?

from ngupload.

mjquinlan2000 avatar mjquinlan2000 commented on July 26, 2024

@twilson63 Thanks for the heads up. Much like @yesnault , I deal mainly in JSON responses as well and did not consider the case where the server might actually intend to serve up a plain text response. I've modified the code to handle both scenarios. Seems to work fine in my application as well as your examples:

var content = iframe.contents().find('body').text()
// Attempt to parse JSON response, else return text response
try {
    content = $.parseJSON(iframe.contents().find('body').text());
}catch (e){
    console.log("WARN: XHR response is not valid JSON: '" + content + "'");
}

Then of course you have to check that content is neither null or an empty string after it is processed.

Hopefully that helps

from ngupload.

Siyfion avatar Siyfion commented on July 26, 2024

Is this a bug that's been introduced recently into ngUpload, or in a patch to Google Chrome? Either way, getting the fix into a build & on Bower would be very much appreciated. 😄

from ngupload.

twilson63 avatar twilson63 commented on July 26, 2024

@Siyfion ,

I am not sure what could have changed to introduce this bug, but I will take a look at it.

Thanks

Tom

from ngupload.

Siyfion avatar Siyfion commented on July 26, 2024

@twilson63 I wonder whether it could have been an update to Google Chrome that's caused it, still.. v. odd.

from ngupload.

twilson63 avatar twilson63 commented on July 26, 2024

Hey Guys,

Found it!

Here is the issue:

69974d4#ng-upload.js

var content = iframe.contents().find('body').text();

was changed to

var content = iframe.contents().find('body').html();

which was submitted as a PR by @cristianocd, I think he was consuming images from the response not json.

So when we changed the iframe.body to .html() it throws the <pre> tag in the returned result vs using .text() which returns the correct json string.

I can either revert it back or look at adding some sort of attribute to specify the returning type. One thing to note is that IE will not accept application/json as a return type, so an alternate solution is to ask your server to return text/html or text/plain, which will not attach the <pre>, regardless, we still need to fix this issue, any thoughts on the best approach to handle both cases?

maybe a return type attribute that specifies the mime/type, if image/* then .html(), and if type/html or type/text the .html() if application/json - then .text() and perform a json parse so you get it back as js?

Thoughts?

Thanks

Tom

from ngupload.

Siyfion avatar Siyfion commented on July 26, 2024

Well I would imagine that the majority of people are probably returning JSON, so I think that would probably be the best "default" case.

However, if you're saying that IE wont work with the content header set to application/json, then perhaps we need to add to documentation to the front screen to ensure that JSON is returned as text/plain instead. Perhaps take a good look at what @mjquinlan2000 was suggesting?

from ngupload.

twilson63 avatar twilson63 commented on July 26, 2024

Ok,

I just bumped to version 0.3.8, this should fix the json problem as well as support any folks sending text or other stuff. Let me know if you continue to have issues or other suggestions.

Thanks again for using ngUpload and helping improve it!

Thanks

Tom

from ngupload.

Siyfion avatar Siyfion commented on July 26, 2024

I can happily confirm that this fixes my issue. Might be worth getting everyone else to check their non-JSON stuff works before giving it the 👍 entirely.

from ngupload.

cristianocd avatar cristianocd commented on July 26, 2024

Working 100%. Thanks!

from ngupload.

mariussoutier avatar mariussoutier commented on July 26, 2024

With JSON it works, but a normal response is still wrapped in a "pre" tag. Is this working as intended?

from ngupload.

e-oz avatar e-oz commented on July 26, 2024

Bug still exists.
On pretty legal Content-Type:application/json I receive

Resource interpreted as Document but transferred with MIME type application/json: "url_here".
WARN: XHR response is not valid json

Chrome 28.0.1500.95 m

from ngupload.

e-oz avatar e-oz commented on July 26, 2024

As a workaround, set Content-type to text/html in response.

from ngupload.

adamshaylor avatar adamshaylor commented on July 26, 2024

I too am still seeing content wrapped in <pre> tags. @Jamm’s solution works, although the response has to be run through JSON.parse() and ngUpload logs this message:

WARN: XHR response is not valid json

from ngupload.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.