Как устранить эту ошибку: неожиданный токен o в JSON в позиции 1 в JSON .parse в angular - PullRequest
0 голосов
/ 16 марта 2020

Это ошибка, которую я получаю, когда звоню в бэкэнд-сервис

it's the error when i done the call to backend:

SyntaxError: Unexpected token o in JSON at position 1
    at JSON.parse(<anonymous>)
    at ApplypositionComponent.push../src/app/applyposition/applyposition.component.ts.ApplypositionComponent.submit (applyposition.component.ts:144)
    at Object.eval [as handleEvent] (ApplypositionComponent.html:75)
    at handleEvent (core.js:23107)
    at callWithDebugContext (core.js:24177)
    at Object.debugHandleEvent [as handleEvent] (core.js:23904)
    at dispatchEvent (core.js:20556)
    at core.js:22046
    at SafeSubscriber.schedulerFn [as _next] (core.js:13527)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:196)

это мой сервис:

postCurriculum(curriculum: FileData): Observable<any> {
    const headers = this.auth.getHeadersCurriculum();
    console.log("post", curriculum)
    return 
        this.http.post(this.fnBaseUrl, curriculum, {
            headers: headers   
    })   
}

и вот я Вызовите метод

this.anagrService.postCurriculum(this.filedata).subscribe(
    response => {
})

от почтальона. Нет проблем с angular, машинопись, я получил эту ошибку, когда передал объект файла со статусом 200, но у меня ошибка .. помогите мне, пожалуйста

1 Ответ

0 голосов
/ 16 марта 2020

Попробуйте вот так

 private jsonHeaders = {
    accept: 'application/json'
  };

postCurriculum(curriculum: FileData): Observable<any> {
    const headers = this.auth.getHeadersCurriculum();
    console.log("post", curriculum)
    return 
        this.http.post<any>(this.fnBaseUrl, curriculum, {
            headers: this.jsonHeaders
    }) ;  
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...