【问题标题】:Getting error " JSONP injected script did not invoke callback." using Angular 2 and Server ASP.NET core收到错误“JSONP 注入脚本未调用回调。”使用 Angular 2 和服务器 ASP.NET 核心
【发布时间】:2017-06-16 00:08:39
【问题描述】:

我在客户端和服务器端使用 Angular 2 Asp.NET Web API 核心。

我已经从 Angular 2 客户端对 ASP.NET 核心 Web API 进行了简单的发布调用,如下面的代码所示。

        this.http.
            post("/api/Patient", data, options)
            .map(res => res.json())
            .subscribe(
            res => this.CallBack(res),
            err => this.logError(err));

我的服务器端 ASP 核心 WebAPI 代码如下所示。

public IActionResult Post()
{
// I am using EF and inserting to DB
// Till here everything works fine.
return Ok(obj);
}

当帖子发生时,我们会收到以下错误

net::ERR_CONNECTION_RESET

数据被插入,但是当对象即将被返回时,服务器只是拒绝。此外,当我深入了解错误时,我看到了以下内容。

“JSONP 注入脚本没有调用回调。” JSONP_ERR_WRONG_METHOD : "JSONP 请求必须使用 GET 请求方法。" JSONP_HOME

在我的本地它可以工作,但有时它确实会崩溃。 我目前在 httpwww.smarterasp.net 上托管,并且在该服务器上此错误很常见。

欢迎任何指点。

【问题讨论】:

  • 这可能会有所帮助github.com/angular/angular/issues/8153
  • 感谢@CoderHawk 的帮助。在那个问题中,他们有 JSONP 请求,我正在发出 JSON 请求。不知道为什么我需要处理 JSONP。
  • 能否请您核对一下,同样的帖子请求与邮递员客户端正常工作??
  • 是的,它可以与 PostMan 一起正常工作。但是感谢您指点我使用 PostMan,我更清楚地看到了事情。将调查并回来。再次感谢。
  • @GauravKumarArora 我按照 Pankaj parkar 的建议使用了 Postman,但这个问题现在来自 smarterasp.net。我已经提出了一张票,接下来会尝试看看接下来会发生什么。

标签: angular asp.net-core jsonp asp.net-core-webapi


【解决方案1】:

我知道这听起来很有趣。但是在 POST 中进行修复而不是返回我们发送 JSON 序列化字符串的对象。

public string Post() // <-- this was first a object we changed to string
{
// I am using EF and inserting to DB
// Till here everything works fine.
  return SerializedString;
}

我们确信这是由于 www.smarterasp.net 的托管问题

【讨论】:

    猜你喜欢
    • 2019-05-26
    • 2017-10-20
    • 2016-11-11
    • 2019-04-01
    • 2016-12-16
    • 1970-01-01
    • 2020-02-22
    • 2013-05-10
    • 2014-02-05
    相关资源
    最近更新 更多