SignalR关闭连接

Signalr Close Connection(SignalR关闭连接)
本文介绍了SignalR关闭连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的Web应用程序中创建停止按钮。WebApp会创建指向不同文件的批量快捷方式。我已尝试使用$.connection.shortcutHub.stop(),但出现错误Cannot read property 'shortcutHub' of undefined(anonymous function)

代码如下。我需要在单击stop按钮后停止连接。停止按钮的ID为stopButton

        $(document).ready(function () {
        // initialize the connection to the server
        var progressNotifier = $.connection.shortcutHub;

        // client-side sendMessage function that will be called from the server-side
        progressNotifier.client.sendMessage = function (message, percent) {
            // update progress
            UpdateMessage(message, percent);
        };

        progressNotifier.client.redo = function () {
            redo();
        };

        progressNotifier.client.success = function () {
            success();
        };

        progressNotifier.client.fail = function () {
            fail();
        };


        // establish the connection to the server and start server-side operation
        $.connection.hub.start().done(function () {
            $('#confirmbutton').click(function () {
                jQuery.noConflict();
                document.getElementById('closeButton').setAttribute("class", "btn btn-default hidden");
                $('#myModal').modal('show');
                //document.getElementById('confirmbutton').disabled = true;
                //document.getElementById('barcodepanel').setAttribute("class", "panel panel-default");
                var ticket = getCookie('ticket');
                var path = getCookie('CBSShortcut_Path');
                var checkeddocs = getCheckedBoxes("dcheck");
                var checkedfolders = getCheckedBoxes("fcheck");
                progressNotifier.server.createshortcuts(ticket, path, checkeddocs, checkedfolders);
            });

            $('#stopButton').click(function () {
                document.getElementById('closeButton').setAttribute("class", "btn btn-default");
                document.getElementById('confirmbutton').disabled = false;


                //What do I put here?
            });



        });



        function UpdateMessage(message, percent) {
            // get result div
            var msg = $("#result");
            // set message
            msg.html(message);
            //set value of progress bar
            document.getElementById('closeButton').setAttribute("class", "btn btn-default hidden")
            $('#progressbar').css('width', percent + '%').attr('aria-valuenow', percent);
        }

        function getCookie(cname) {
            var name = cname + "=";
            var ca = document.cookie.split(';');
            for (var i = 0; i < ca.length; i++) {
                var c = ca[i];
                while (c.charAt(0) == ' ') c = c.substring(1);
                if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
            }
            return "";
        }

        function redo() {
            document.getElementById('confirmbutton').disabled = false;
            jQuery.noConflict();
            $('#myModal').modal('hide');
        }


        // Pass the checkbox name to the function
        function getCheckedBoxes(chkboxclass) {
            var checkboxes = document.getElementsByClassName(chkboxclass);
            var checkboxesChecked = [];
            var ids = "";
            // loop over them all
            for (var i = 0; i < checkboxes.length; i++) {
                // And stick the checked ones onto an array...
                if (checkboxes[i].checked) {
                    checkboxesChecked.push(checkboxes[i]);
                    ids = ids + checkboxes[i].getAttribute("Name") + ",";
                }
            }
            // Return the array if it is non-empty, or null
            //return checkboxesChecked.length > 0 ? checkboxesChecked : null;
            return ids;
        }
    }
);`

如有任何帮助,我们将不胜感激。我试过谷歌扔给我的所有东西(大部分都是堆积溢出网站),但我仍然有同样的问题。

推荐答案

您是否尝试过:

$.connection.hub.stop().done(function() {
    alert('stopped');
});

它会起作用的。

这篇关于SignalR关闭连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)