Angular http client not working with translation on in IOS chrome browser?

天涯浪子 提交于 2021-01-05 07:07:41

问题


I have angular project built in angular 10. I am getting issue in calling api from IOS chrome browser when i turn on google translation from browser.

If i do not turn on translation it is giving me correct response for API

However when i turn on translation i am getting this error.

InvalidAccessError The object does not support the operation or argument

Error is happening only when i do translation from browser if i do translation from settings in Iphone the it is working fine.

and it is also working fine in all browsers in laptop.

If use javascript fetch function instead of angular HttpClient then it is working fine with HttpClient request is not even going to server. It is giving error even before sending request.


回答1:


Its because HTTPClient expects a json in response by default and when you turn on translation, its no more a json. Try receiving response like

this.http.post(this.url, body, {responseType: 'text'}).subscribe((res)=> console.log(res));

also body should be a json like

body=JSON.stringify(data);

if it prints then if you feel its not a json then map it to javascript object via your code, if it seems a json then use

JSON.parse(res);


来源:https://stackoverflow.com/questions/65247153/angular-http-client-not-working-with-translation-on-in-ios-chrome-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!