一、本地外部引用

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
.container {
background-color: #99CCFF;
border: thick solid #808080;
padding: 20px;
margin: 20px;
}
</style>
</head>
<body>
<div class="container">
<input type="text" id="message" />
<input type="button" id="sendmessage" value="Send" />
<input type="hidden" id="displayname" />
<ul id="discussion"></ul>
</div>
<script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.js"></script>
<script src="http://localhost:52992/lib/signalr/dist/browser/signalr.js"></script>
<script type="text/javascript">
"use strict";
$(function () { var connection = new signalR.HubConnectionBuilder().withUrl("http://localhost:52992/chatHub").build();
// var connection = $.connection('http://localhost:8000/signalr');
// connection
connection.start().then(function () {
console.log("链接成功!");
}).catch(function (err) {
return console.error(err.toString());
});
//接受消息
connection.on("ReceiveMessage", function (message) {
console.log(message);
var obj = JSON.stringify(message);
console.log(obj);
//var msg = message.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
//var encodedMsg = msg;
//var li = document.createElement("li");
//li.textContent = encodedMsg;
//document.getElementById("messagesList").appendChild(li);
});
$("#sendmessage").click(function() {
//发送消息
var msgObj = {
"Type": 1,
"LoginUserId": 3100003640,
"UserName": "孙凤才",
"GroupId": 1,
"Content": "消息发送成功",
"RecordId": 140,
"Index": 137,
};
connection.invoke("SendMessage", "sdad",JSON.stringify(msgObj)).catch(function (err) {
return console.error(err.toString());
});
});
});
</script>
</body>
</html>

后面几点要注意:

解决方式:

app.UseCors(builder =>
{
builder.SetIsOriginAllowed(origin => true)
.AllowAnyHeader()
.WithMethods("GET", "POST")
.AllowCredentials();
});

即最终是

三、Signalr外部链接的更多相关文章

  1. Pyqt 打开外部链接的几种方法

    Pyqt 触发一个事件,打开外部链接,我找到了这个方法,供大家参考 1. QDesktopServices 的openUrl 方法 QtGui.QDesktopServices.openUrl(QtC ...

  2. Kubernetes的三种外部访问方式:NodePort、LoadBalancer和Ingress(转发)

    原文 http://cloud.51cto.com/art/201804/570386.htm Kubernetes的三种外部访问方式:NodePort.LoadBalancer和Ingress 最近 ...

  3. vue项目跳转到外部链接

    vue项目中遇到一个打印的功能.思考之后决定点击按钮,跳转到一个HTML页面(后台写的),利用window.print()方法调用浏览器的打印的功能. 所以,现在的问题是,怎样跳转到外部链接.开发vu ...

  4. 如何给wordpress外部链接自动添加nofollow

    wordpress多作者博客可以丰富网站的内容,但同时也会产生一些无关的链接,例如有些投机的人会考虑在文章中随意添加外部链接,如果你不想给这些外部链接传递权重,你需要给这些外部链接加上 rel=&qu ...

  5. PHP过滤外部链接及外部图片 添加rel="nofollow"属性

    原来站内很多文章都是摘录的外部文章,文章里很多链接要么是时间久了失效了,要么就是一些测试的网址,如:http://localhost/ 之类的,链接多了的话,就形成站内很多死链接,这对SEO优化是很不 ...

  6. (转)DEDECMS 如何让栏目外部链接在新窗口中打开

    近遇到一个问题,就是dedecms的导航,是用外部链接的,但是原窗口打开不好看,新窗口打开好点.OK,放狗... 1. 查找模板中的head.htm将<li><a href='[fi ...

  7. 用CSS指定外部链接的样式

    大部分的信息类网站,比如维基百科,都会对外部链接(<a>标签)指定特定的样式.作为用户,一眼就知道该链接是指向另一个站点的资源是很好的体验.许多网站在服务器端做外部链接检查,添加一个`re ...

  8. [Vue] vue跳转外部链接

    问题 vue 跳转外部链接问题,当跳转的时候会添加在当前地址后面 var url = 'www.baidu.com' //跳转1 window.localtion.href = url //跳转2 w ...

  9. ios外部链接或者app唤起自己的app

    唤起自己的app,其实都是通过链接,关于这个需要了解下scheme,自己和调用方对接下协议,这里只是说明下到自己app指定页的问题 唤起自己的app分为两种情况 一.自己的app已经启动,那么唤起自己 ...

随机推荐

  1. spark MLlib 概念 6:ALS(Alternating Least Squares) or (ALS-WR)

    Large-scale Parallel Collaborative Filtering for the Netflix Prize http://www.hpl.hp.com/personal/Ro ...

  2. note: Spanner: Google’s Globally-Distributed Database

    1. Abstract & introduction ref:http://static.googleusercontent.com/media/research.google.com/zh- ...

  3. Python统计学statistics实战

    python机器学习-乳腺癌细胞挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003&u ...

  4. ControlTemplate in WPF —— ItemsControl

    <ItemsControl Margin=" ItemsSource="{Binding Source={StaticResource myTodoList}}"& ...

  5. C++统计程序运行时间代码片段

    因为经常需要统计代码的运行时间,所以计时功能就显得很重要, 记录一下现在喜欢用的计时方式,供日后查阅. 1.下面是计时主函数, bool TimeStaticMine(int id,const cha ...

  6. bootstrap datetimepicker、bootstrap datepicker日期组件对范围的简单封装

    1.bootstrap datepicker 使用 <div class="row form-group"> <label class="control ...

  7. Struts---多文件上传、单文件下载

    struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUB ...

  8. PPT添加节

    如果你要做很多PPT,而又不想把PPT分到很多个文件里,你可以在PPT中添加节(Section).这样你的PPT就像书本一样,一章一章的,非常方便.

  9. C++中sort函数使用方法

    一.sort函数 1.sort函数包含在头文件为#include<algorithm>的c++标准库中,调用标准库里的排序方法可以实现对数据的排序,但是sort函数是如何实现的,我们不用考 ...

  10. heartbeat双主高可用

    一.基础配置 1.hostnamectl set-hostname node1 (node2) 2.[root@node1 ~]# cat /etc/hosts     192.168.40.128 ...