Signalr-Verbindung Schließen

Ich versuche, erstellen Sie eine Stopp-Schaltfläche in meiner webapp. Die webapp erstellt bulk Verknüpfungen zu anderen Dateien. Ich habe versucht mit $.connection.shortcutHub.stop() aber dieser kommt mit einer Fehlermeldung, die sagen Cannot read property 'shortcutHub' of undefined(anonymous function)

Den code unten ist. Ich muss die Verbindung beendet werden, sobald die stop - Schaltfläche geklickt wurde. Die stop-Taste id ist 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;
        }
    }
);`

Jede Hilfe ist willkommen. Ich habe alles versucht, was google geworfen hat meinen Weg (die wurde meist stackoverflow-Seiten) und ich bin immer noch mit dem gleichen problem.

InformationsquelleAutor JohZant | 2016-07-28
Schreibe einen Kommentar