2017-02-15 119 views
-2

意外字符在解析值遇到:S.路徑 '',第0行,位置0Angular 2 Http Post Error | JSON

Angular2交碼

enter image description here

結果:

enter image description here

+2

請隨時發佈您的代碼在你的問題* *代碼以及任何錯誤消息:) – Alex

+0

請閱讀如何在此處提問:http://stackoverflow.com/help/how-to-ask – CodeLikeBeaker

回答

1

使用Content-Type: application/x-www-form-urlencoded時,請使用改爲;

import { URLSearchParams } from '@angular/http'; 

和您的文章函數內部,不發你的對象body,而不是這樣做:

let postBody = new URLSearchParams(); 
postBody.set('yourProperty1', body.yourProperty1); 
postBody.set('yourProperty12', body.yourProperty2); 
... 

return this._htpp.post('yourUrl', postBody, options) 
    .map(...)