Guest User

Untitled

a guest
Jan 23rd, 2018
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <div class="row">
  2. <div class="col-md-12">
  3. <div id="messagesTable">
  4. </div>
  5. </div>
  6. </div>
  7.  
  8. @section scripts
  9. {
  10. <script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script>
  11. <!--Reference the autogenerated SignalR hub script. -->
  12. <script src="~/signalr/hubs"></script>
  13. <script type="text/javascript">
  14.  
  15. var link = '@Url.Action("GetMessages", "Home")';
  16. $(function () {
  17. // Declare a proxy to reference the hub. v
  18. var notifications = $.connection.chatHub;
  19.  
  20. // Create a function that the hub can call to broadcast messages.
  21. notifications.client.updateMessages = function () { getAllMessages() };
  22.  
  23. // Start the connection.
  24. $.connection.hub.start()
  25. .done(function () { getAllMessages(); })
  26. .fail(function (e) { alert(e); }); });
  27.  
  28. function getAllMessages() {
  29. var tbl = $('#messagesTable');
  30.  
  31. $.ajax({
  32. cache: false,
  33. url: link,
  34. dataType: "json",
  35. type: 'GET'
  36. })
  37. .success(function (data) {
  38. var array = String(data).split(",");
  39. tbl.empty()
  40.  
  41. for (var i in array) {
  42. tbl.append('<div>Insurer: ' + array[i] + '</div>');
  43. }
  44. })
  45. .error(function (response) { alert(response) }); }
  46.  
  47. </script>
  48. }
Add Comment
Please, Sign In to add comment