detail":"JSON parse error - Expecting value: line 1 column 1 (char 0)

detail":"JSON parse error - Expecting value: line 1 column 1 (char 0)

Return 400 error when invoking the interface of the details

{detail":"JSON parse error - Expecting value: line 1 column 1 (char 0)"}

The reason is that there is a problem transferring data format, do not use , contentType: 'application/json'enough

Ajax requests using a reqwest, the original code

 postBill() {
            let self = this;
            let token = getQueryVariable('token');
            this.userToken = token;
            let addFamily = 0;
            if(self.is_add_to_family)
                addFamily = 1;
            if (token) {
                reqwest({
                    url: 'http://127.0.0.1:8000/api/v1/bill/Income/?token=' + token
                    , method: "POST"
                    , type: 'json'
                    , contentType: 'application/json'
                    , data: {
                        bill_type: self.bill_type,
                        money: self.money,
                        is_add_to_family: self.is_add_to_family,
                        remarks: self.remarks,
                        time: self.time,
                        concrete_type: self.concrete_type
                    }
                    , success: function (resp) {
                        //
                    }
                })
            }
        },

Later changed

postBill() {
            let self = this;
            let token = getQueryVariable('token');
            this.userToken = token;
            let addFamily = 0;
            if(self.is_add_to_family)
                addFamily = 1;
            if (token) {
                reqwest({
                      url: 'http://127.0.0.1:8000/api/v1/bill/Income/?token=' + token
                    , method: "POST"
                    , type: 'json'
                    , data: {bill_type: self.bill_type,
                        money: self.money,
                        is_add_to_family: self.is_add_to_family,
                        remarks: self.remarks,
                        time: self.time,
                        concrete_type: self.concrete_type
                    }
                    , success: function (resp) {
                        qwery('#content').html(resp)
                    }
                })
            }
        },

Concrete is deleted , contentType: 'application/json', because it is solved

You can see the reason why you need to send ajax json data set contentType: "application / json" and ajax set contentType: "application / json" role

Published 62 original articles · won praise 33 · views 10000 +

Guess you like

Origin blog.csdn.net/zjbyough/article/details/103570747