Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

transformResponse data is string in IE11 #8590

Closed
sjorobekov opened this issue Aug 13, 2014 · 11 comments
Closed

transformResponse data is string in IE11 #8590

sjorobekov opened this issue Aug 13, 2014 · 11 comments

Comments

@sjorobekov
Copy link

I'm using transformResponse in $resource service. Below is link for plunker.
I'm using httpBackend, and everything is fine. But If use real backend, data comes as string, and only in IE (tested in IE11).
http://plnkr.co/edit/XmSGFyfSgvPsbTIi7wlm?p=preview

@jeffbcross
Copy link
Contributor

I created a plunker that loads a real json array, and could reproduce the issue (serialized in Chrome, string in IE): http://plnkr.co/edit/E7tgLjZkkrCyOxLsncG5?p=preview

@jeffbcross jeffbcross added this to the 1.3.0 milestone Aug 13, 2014
@jeffbcross jeffbcross removed their assignment Aug 13, 2014
@IgorMinar
Copy link
Contributor

IE doesn't seem to support responseType=json, it does support other responseTypes though. bizare.

http://msdn.microsoft.com/en-us/library/ie/hh872882(v=vs.85).aspx

We can detect this and parse the string ourselves.

@IgorMinar IgorMinar modified the milestones: 1.3.0-rc.1, 1.3.0 Aug 29, 2014
@caitp
Copy link
Contributor

caitp commented Aug 30, 2014

webkit had a similar issue until about a year ago, iirc. I think this should already be handled by the try/catch no? I would expect this same logic to also work for the IE case

@IgorMinar
Copy link
Contributor

I think the issue is that it doesn't throw. It just ignores the responseType value and doesn't parse the response .

@caitp
Copy link
Contributor

caitp commented Aug 30, 2014

Yeah but I don't think transformResponse cares what responseType is, iirc --- just "if response is a string"

@thebigredgeek
Copy link
Contributor

I am assuming it is passing this if statement in the try catch, correct? Why not simply check for type string, if responseType === 'json'. If string, parse it and override the variable with the parsed value and continue?

@caitp
Copy link
Contributor

caitp commented Aug 31, 2014

What happens is, if we get a response that is a string, and we decide it looks like a JSON payload, we parse it. Yes, there are cases where this doesn't do what you expect (like, valid JSON payloads such as null or 123 or "foo", or non-json payloads such as [{foo}] where [{/}] are your interpolation markers) --- but if it's a string that looks like a JSON object/array literal, we try to parse it as JSON, regardless of what responseType is.

This isn't perfect, but I'm having a hard time seeing the issue

@thebigredgeek
Copy link
Contributor

Can the OP create a test case? Perhaps that would help?

@petebacondarwin
Copy link
Contributor

Here is a minimal plunker (stripping out ngResource):

Angular 1.2: http://plnkr.co/edit/FbI4OmG99dFG5hR3gShy?p=preview
Angular Latest: http://plnkr.co/edit/YCI1hJ2OniEqkHG27yLr?p=preview

I can't reproduce the issue with v1.2 on IE 11 (Win8), IE 10 (Win8) or IE 9 (WinXP).

@petebacondarwin
Copy link
Contributor

Right! So the problem is that if you provide your own transformResponse function then the default one is overwritten. Therefore our function, which does the JSON conversion, in $http.defaults.transformResponse is never called.

You can see it being re-applied in this plunk: http://plnkr.co/edit/IanQvLYqWTmyBFNLRYIj?p=preview

I think this is not a valid issue other than perhaps we should clarify what happens to the default transform function if you provide a specific one.

@tbosch
Copy link
Contributor

tbosch commented Sep 3, 2014

@petebacondarwin Could create a docs change for this then? And maybe also a hint how to invoke the original transformer like you did in your example? Assigning this to you as well...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants