laravel Vue 资源发布请求内容类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39439807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Vue Resource Post Request Content-Type
提问by Ramazan APAYDIN
Vue-Resource Post Request:
Vue-Resource Post 请求:
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.
请求发送为 Content-Type:"application/json;charset=utf-8" 但 PHP Post 无法显示任何数据。
Set Up Header Vue-Resource:
设置标题 Vue-Resource:
request.headers.set('Content-Type', '');
request.headers.set('Content-Type', '');
But Request Content-Type:", multipart/form-data; boundary=----WebKitFormBoundaryTsrUACAFB1wuhFOR"
但是请求 Content-Type:", multipart/form-data; boundary=----WebKitFormBoundaryTsrUACAFB1wuhFOR"
there is a comma at the beginning of the query.
查询的开头有一个逗号。
Jquery Post Request:
Jquery 发布请求:
$.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"
相同的查询可与 jQuery 无缝协作。jQuery 内容类型:“multipart/form-data;boundary=----WebKitFormBoundaryTsrUACAFB1wuhFOR”
回答by Zacky Pickholz
Please try instead to post a simple JSON object and enable the 'emulateJSON' vue-resource option:
请尝试发布一个简单的 JSON 对象并启用 'emulateJSON' vue-resource 选项:
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);
});