Comments (16)
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.
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.
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.
@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.
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.
@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.
@twilson63 I wonder whether it could have been an update to Google Chrome that's caused it, still.. v. odd.
from ngupload.
Hey Guys,
Found it!
Here is the issue:
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.
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.
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.
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.
Working 100%. Thanks!
from ngupload.
With JSON it works, but a normal response is still wrapped in a "pre" tag. Is this working as intended?
from ngupload.
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.
As a workaround, set Content-type to text/html in response.
from ngupload.
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)
- ngUpload not working on Firefox 27 Mac - returns HTML instead of JSON
- getting a warning in console
- How to prefix file name that is uploaded HOT 10
- Minified version causing form submitted multiple times HOT 7
- 404 not found HOT 2
- Error handling HOT 6
- Setting custom headers HOT 8
- Auto start upload HOT 3
- custom headers using CORS in IE8 HOT 1
- Minified file not updated HOT 1
- $isLoading should be $isUploading in the readme HOT 1
- ng-upload executing multiple times
- ngUpload is not working HOT 3
- ng-upload.min.js is broken HOT 2
- How can we implement the progress bar for ngUpload? HOT 2
- Bower package is out-of-date HOT 3
- Hidden inputs do not work for objects
- Can we get upload percent in $scope? HOT 1
- BeforeSumbit executes after submit
- Is it possible to register the package on npm? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngupload.