首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular/SignalR错误:无法启动连接。SyntaxError: JSON输入意外结束

Angular/SignalR错误:无法启动连接。SyntaxError: JSON输入意外结束
EN

Stack Overflow用户
提问于 2018-02-21 21:48:04
回答 1查看 1.7K关注 0票数 2

尝试创建简单的angular/signalR应用程序。

我的Hub类:

代码语言:javascript
复制
namespace Gameserver.Hubs
{
    public class SignalRHub : Hub
    {
        public Task Send()
        {
            return Clients.All.InvokeAsync("Send", "Message from the server");
        }
    }
}

我的startup.cs:

代码语言:javascript
复制
public partial class Startup
{
    public void Configure(IAppBuilder app)
    {
        app.MapSignalR();
    }
}

和一个组件:

代码语言:javascript
复制
import { Component, OnInit } from '@angular/core';
import { HubConnection } from '@aspnet/signalr-client';

export class CoreComponent implements OnInit 
{
  private connection: HubConnection;

  ngOnInit(){
    this.connection = new HubConnection('http://localhost:49756/signalr/');

    this.connection.on('send', data =>{
      console.log(data);
    })

    this.connection.start()
      .then(() => console.log('connected'))
      .catch(err => console.log('Error while establishing connection: ' + err));
  }

运行后,从Loggers.js获得此错误

代码语言:javascript
复制
Error: Failed to start the connection. SyntaxError: Unexpected end of JSON input

有人能帮我纠正这个错误吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-22 14:06:06

在尝试了另外两个包之后,我发现其中一个运行良好。https://github.com/HNeukermans/ng2-signalR https://www.npmjs.com/package/ng2-signalr

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48907590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档