Angular HTTP客户端无法在IOS chrome浏览器中进行翻译? [英] Angular http client not working with translation on in IOS chrome browser?

查看:103
本文介绍了Angular HTTP客户端无法在IOS chrome浏览器中进行翻译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在angular 10中内置了angular项目.当我从浏览器中打开google翻译时,从iOS chrome浏览器调用api时遇到问题.

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.

如果我不开启翻译功能,则会为我提供正确的API响应

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对象不支持该操作或参数

仅当我通过Iphone中的设置进行翻译时,才发生从浏览器进行翻译的错误,这一切正常.

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.

如果使用javascript fetch 函数而不是有角的 HttpClient ,则与 HttpClient 的请求工作正常,甚至不会发送到服务器.甚至在发送请求之前就给出了错误.

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.

推荐答案

这是因为HTTPClient默认情况下期望json作为响应,并且当您打开翻译时,它不再是json.尝试接收类似的回复

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

body也应为json

also body should be a json like

body=JSON.stringify(data);

如果打印,则如果您感觉它不是json,则通过代码将其映射到javascript对象;如果它看起来是json,则使用

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

这篇关于Angular HTTP客户端无法在IOS chrome浏览器中进行翻译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆