Vue-resource: Won't decode JSON

Created on 3 Jul 2016  路  5Comments  路  Source: pagekit/vue-resource

On my production server, vue-resource won't unwrap a json response, despite having the correct Content-Type headers.

The issue only appears in chrome and is reproducible:

Production Server

On my Testserver, the very same line produces the following output (compare data attribute):

Test Server

I tried removing the custom X- headers and other things, but I just can't get it to run properly..

Most helpful comment

Yup.
Solved the Issue by using a custom interceptor:

Vue.http.interceptors.unshift(function(request, next) {
    next(function(response) {
        if(typeof response.headers['content-type'] != 'undefined') {
            response.headers['Content-Type'] = response.headers['content-type'];
        }
    });
});

All 5 comments

I think I've found the error. the body interceptor explicity looks for Content-Type in uppercase letters.

I'm using SPDY with my nginx server and it requires headers to be lowercase.
Therefor the content-type header is not found and thy body is not converted into an object.

Yup.
Solved the Issue by using a custom interceptor:

Vue.http.interceptors.unshift(function(request, next) {
    next(function(response) {
        if(typeof response.headers['content-type'] != 'undefined') {
            response.headers['Content-Type'] = response.headers['content-type'];
        }
    });
});

got the same problem, thx for your solution馃憤

just an FYI - outdated versions of PHP cause this issue as well. need to be >5.4 i believe.

Hey guys, curious to know and it's my first time playing around with Vue, where do I go about applying that solution?

Do I patch it in my main.js - where all my vue components are being instantiated from? or do I use it when I make a HTTP request ?

I am facing the same issue with my v-for inconsistency with my local and production server.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

laizhenhai88 picture laizhenhai88  路  4Comments

ionutvelicu picture ionutvelicu  路  5Comments

yozman picture yozman  路  6Comments

nivv picture nivv  路  4Comments

EmilMoe picture EmilMoe  路  5Comments