Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mohamedJamal's avatar

response()->json() return different types value after deploy

My code was working perfectly at homestead and return JSON as I expect when I deploy my APP the code does not return JSON like image >> https://ibb.co/LRZNhJr

Code

        return response()->json($cart);
// and I tried
        return response(json_encode($cart));

0 likes
8 replies
Amaury's avatar

It is difficult to help you if you not give us more information…

mohamedJamal's avatar
                    var self = this;
                    axios.post( '/'+window.App.lang+'/cart/add/'+this.slug)
                        .catch(error => {
                            flash(error.response.data,'danger');
                        })
                        .then(function (response) {
                            if(response.status === 200){
                            console.log(typeof response.data,typeof response,response);

                                self.$root.cart = response.data;
                                flash(self.$options.filters.langJson('Added to cart'));
                            }
                        });

i tested php and is json_encode working but the problem comes from axios i think, type of response.data is string i dont know why?

Amaury's avatar

@mohamedjamal Glad you solved the problem. By the way, when I have issue with a json file, I always check it with jsonlint…

1 like

Please or to participate in this conversation.