2017-02-15 118 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(...)