2016-09-11 3 views
3

뷰 - 자원 POST 요청 :뷰 자원 POST 요청의 콘텐츠 유형

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

요청 콘텐츠 형식으로 전송된다 : "응용 프로그램/JSON; 문자셋 = UTF-8"하지만 데이터는 PHP에 의해 표시 할 수 없습니다 게시하다.

설정까지 헤더 뷰 - 리소스 :

request.headers.set ('콘텐츠 유형', '');

그러나 요청의 Content-Type : "다중/폼 데이터, 경계 = ---- WebKitFormBoundaryTsrUACAFB1wuhFOR"

쿼리의 시작 부분에 쉼표가 있습니다.

JQuery와 POST 요청 :

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

같은 쿼리가 jQuery를 함께 완벽하게 작동합니다. jQuery를 콘텐츠 유형 : "다중/폼 데이터, 경계 = ---- WebKitFormBoundaryTsrUACAFB1wuhFOR"

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

+0

게시 된 데이터를 표시 할 수없는 이유는 무엇입니까? 어떤 오류가 발생합니까? 지금 테스트하는 동안 콘텐츠 유형을 설정할 수는 없지만 중요한 것은 아닌 것 같습니다. Laravel은 파일 업로드만으로 데이터를 수신했습니다. –

답변

1

간단한 JSON 객체를 게시하고 'emulateJSON'VUE-자원을 활성화하는 대신 시도하십시오 옵션 :

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); 
    });