asp.net - 使用 Angular 从 webapi 检索单个值

标签 asp.net angular typescript

目标:在 Angular 中检索单个值“test”。

问题:我收到错误消息

Error: SyntaxError: Unexpected token e in JSON at position 1 at JSON.parse ()

我缺少什么语法?


ASP.NET

// https://localhost:44353/api/Jobadvertisement/VVValidate/4
[HttpGet("VVValidate/{id:int}")]
public ActionResult<String> VVValidate(int id)
{
    return "test";
}

Angular

const url = environment.url

let asdfasdf2 = url + 'api/Jobadvertisement/VVValidate/' + "4";

var dsfsdssf = this.http.get(asdfasdf2).subscribe(data => {

  console.log(data);

});

enter image description here

enter image description here

最佳答案

你能尝试在 Angular 中使用 httpOptions 吗:

const url = environment.url;
let asdfasdf2 = url + 'api/Jobadvertisement/VVValidate/' + "4"; 
var dsfsdssf = this.http.get(asdfasdf2, { responseType: 'text' }).subscribe(data => { console.log(data); });

关于asp.net - 使用 Angular 从 webapi 检索单个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56824740/

相关文章:

c# - AddToRole 失败并在用户名中输入 + 号?

asp.net - 有条件地在 HTML 元素上设置 Disabled 和 Checked 属性

javascript - 带有 __underscores__ 的 typeorm 返回字段中的查找函数

javascript - filereader.onload 中的函数未在 javascript 中执行

typescript - Gulp-watch typescript 文件并仅发布更改的文件

c# - 我可以允许匿名用户和事件目录用户浏览同一个 IIS 7.5 站点吗?

c# - 获取html页面上的所有链接?

javascript - 使用 Ionic CSS 动态附加子节点

angular - K8s/Angular CORS 问题 REST 服务器

angular - 如何在 Angular 9 中的所有组件中使用带有表单的单个模式?