typescript - 在获取数据时将 XMLHttpRequest 转换为 http 请求
问题描述
我正在尝试使用 http get 方法根据从后端提交的名称搜索数据..我收到以下错误..
从源“http://localhost:4200”访问“localhost:3300/secure/students/search/?uname=def”的 XMLHttpRequest 已被 CORS 策略阻止:跨源请求仅支持协议方案:http,数据,铬,铬扩展,铬不受信任,https。
这是我来自 component.ts 文件的代码:-(我从模板文件中的表单中获取数据)
export class SearchStudentComponent implements OnInit {
`uname :string = ' ';
constructor(private http: HttpClient) { }
`ngOnInit(): void {`
}`
Searchform(searchform:NgForm)
{
this.Uname = searchform.value.uname;
console.log("user name is"+ this.Uname);
console.log('localhost:3300/secure/students/search/?uname='+ this.Uname);
this.http.get('localhost:3300/secure/students/search/?uname='+ this.Uname).subscribe(data=>console.log(data));
}
解决方案
推荐阅读
- python - 为文本数据抓取网站 html 时出现 lxml 错误。尝试了几次迭代
- javascript - 通过单击javascript减慢滚动页面
- c# - WPF:在后面的代码中访问转换后的 Canvas 坐标
- rabbitmq - RabbitMQ 管理插件中的配置条目
- php - fsockopen 总是 操作超时
- excel - 如何使用 Power Query 在一行中删除重复项?
- excel - 如何将多个 Excel 工作表迁移到一个主工作簿
- python - 在 tablewidget Qt5 Python 中显示 CSV 文件
- r - 如何将字符串转换为R中的嵌套列表?
- kql - 使用 KQL 输出多个汇总列表