Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue Resource Post Request Content-Type

Vue-Resource Post Request:

this.$http.post(form.action, new FormData(form)).then(function (response) {
    FetchResponse.fetch(this, response.data)
})

Request are Send as Content-Type:"application/json;charset=utf-8" But No data can be displayed by PHP Post.

Set Up Header Vue-Resource:

request.headers.set('Content-Type', '');

But Request Content-Type:", multipart/form-data; boundary=----WebKitFormBoundaryTsrUACAFB1wuhFOR"

there is a comma at the beginning of the query.

Jquery Post Request:

$.ajax({
    url     : form.action,
    type    : 'POST',
    data    : new FormData(form),
    success : function (reqData) {
        FetchResponse.fetch(ss, reqData)
    },
});

The same query works seamlessly with jQuery. jQuery Content-Type: "multipart/form-data; boundary=----WebKitFormBoundaryTsrUACAFB1wuhFOR"

Issue: https://github.com/vuejs/vue-resource/issues/398

like image 358
Ramazan APAYDIN Avatar asked Sep 11 '16 19:09

Ramazan APAYDIN


1 Answers

Please try instead to post a simple JSON object and enable the 'emulateJSON' vue-resource option:

const formData = {
    someProp: this.someProp,
    someValue: 'some value'
};

this.$http.post(this.postUrl, formData, {emulateJSON: true})
   .then(response => {
        console.log(response.body);
    }, response => {
       console.error(response.body);
    });
like image 179
Zacky Pickholz Avatar answered Oct 28 '22 00:10

Zacky Pickholz