欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS實(shí)現(xiàn)websocket長(zhǎng)輪詢(xún)實(shí)時(shí)消息提示的效果

 更新時(shí)間:2017年10月10日 11:07:35   作者:祈澈姑娘  
這篇文章主要介紹了JS實(shí)現(xiàn)websocket長(zhǎng)輪詢(xún)實(shí)時(shí)消息提示的效果的相關(guān)資料,需要的朋友可以參考下

效果圖如下:

參考代碼如下:

jsp代碼:

<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<div class="page-header navbar navbar-fixed-top">
  <div class="page-header-inner">
    <div class="page-logo">
      <a href="<c:url value=" rel="external nofollow" rel="external nofollow" /"/>"><img
        src="<c:url value="/img/logo.png"/>" style="height: 14px" alt="logo"
        class="logo-default" /></a>
      <div class="menu-toggler sidebar-toggler hide"></div>
    </div>
    <a href="javascript:;" rel="external nofollow" rel="external nofollow" class="menu-toggler responsive-toggler"
      data-toggle="collapse" data-target=".navbar-collapse"></a>
    <div class="top-menu">
      <ul class="nav navbar-nav pull-right">
        <li class="dropdown dropdown-alert"><a href="#" rel="external nofollow" rel="external nofollow" 
          class="dropdown-toggle" data-toggle="dropdown"
          data-hover="dropdown" data-close-others="true"> <span
            class="badge pull-left"></span><label class="hidden-sm">報(bào)警</label><i
            class="fa fa-bell"></i>
        </a>
          <ul class="dropdown-menu">
          </ul></li>
        <li class="dropdown dropdown-user"><a href="#" rel="external nofollow" rel="external nofollow" 
          class="dropdown-toggle" data-toggle="dropdown"
          data-hover="dropdown" data-close-others="true"> <span
            class="username username-hide-on-mobile">你好,${sessionScope.username}</span>
            <i class="fa fa-angle-down"></i>
        </a>
          <ul class="dropdown-menu">
            <li><a href="javascript:;" rel="external nofollow" rel="external nofollow" id="updatePass"><i
                class="icon-lock"></i>修改密碼</a></li>
            <li><a href="<c:url value=" rel="external nofollow" rel="external nofollow" /logout"/> "><i
                class="icon-key"></i>退出登錄</a></li>
          </ul></li>
      </ul>
    </div>
  </div>
</div>
<div class="clearfix"></div>
<script>
  //toastr.sos(num1)
</script>
<script type="text/javascript"
  src="http://cdn.bootcss.com/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript"
  src="http://cdn.bootcss.com/sockjs-client/1.1.1/sockjs.js"></script>
<script type="text/javascript">
  function wsPath() {
    var pathName = window.document.location.pathname;
    var host = window.location.host;
    var projectName = pathName.substring(0,
        pathName.substr(1).indexOf('/') + 1);
    return (host + projectName);
  }
  wsPath = wsPath();
  var websocket = null;
  if ('WebSocket' in window) {
    websocket = new WebSocket("ws://" + wsPath + "/websocket/socketServer");
  } else if ('MozWebSocket' in window) {
    websocket = new MozWebSocket("ws://" + wsPath
        + "/bison/websocket/socketServer");
  } else {
    websocket = new SockJS("http://" + wsPath
        + "/bison/sockjs/socketServer");
  }
  websocket.onmessage = onMessage;
  websocket.onope = onOpen;
  websocket.onerror = onError;
  websocket.onclose = onClose;
  function onOpen() {
  }
  function onMessage(evt) {
    var $uncheckedAlertMenuBtn = $("a.dropdown-toggle", $uncheckedAlertMenu);
    var $uncheckedAlertBadge = $("span.badge", $uncheckedAlertMenuBtn);
    var $uncheckedAlertMenu = $('li.dropdown-alert');
    var $uncheckedAlertList = $('ul', $uncheckedAlertMenu);
    var a = $uncheckedAlertBadge.html();
    $uncheckedAlertBadge.html(Number(a) + 1);
    //判斷報(bào)警類(lèi)型 如果是位置偏移,place+1
    if (evt.data == "1") {
      var count;
      var a = $("#number").html();
      if (a == null) {
        count = 1;
        $uncheckedAlertList
            .prepend('<li class="place-alert"><a href="alert?menuId=274" rel="external nofollow" rel="external nofollow" > <font color="red" id="place-alert">'
                + "位置報(bào)警(<font id ='number'>"
                + count
                + "</font>)" + '</font></a></li>');
      } else {
        count = Number(a) + 1;
        $("#place-alert").html(
            "位置偏移(<font id='number'>" + count + "</font>)");
      }
    }
    if (evt.data == "0") {
      var count;
      var a = $("#snum").html();
      if (a == null) {
        count = 1;
        $uncheckedAlertList
            .prepend('<li class="sos-alert"> <a href="alert?menuId=274" rel="external nofollow" rel="external nofollow" ><font color="red" id="sos-alert">'
                + "SOS報(bào)警(<font id='snum'>"
                + count
                + ")</font>"
                + '</font></a></li>');
      } else {
        count = Number(a) + 1;
        $("#sos-alert").html(
            "SOS報(bào)警(<font id='snum'>" + count + "</font>)");
      }
    }
  }
  function onError() {
    websocket.close();
  }
  function onClose() {
  }
  window.close = function() {
    websocket.onclose();
  }
</script>

總結(jié)

以上所述是小編給大家介紹的JS實(shí)現(xiàn)websocket長(zhǎng)輪詢(xún)實(shí)時(shí)消息提示的效果,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Ajax請(qǐng)求時(shí)無(wú)法重定向的問(wèn)題解決代碼詳解

    Ajax請(qǐng)求時(shí)無(wú)法重定向的問(wèn)題解決代碼詳解

    這篇文章主要介紹了Ajax請(qǐng)求時(shí)無(wú)法重定向的問(wèn)題解決代碼詳解,當(dāng)使用Ajax請(qǐng)求時(shí),如果后臺(tái)進(jìn)行重定向到其他頁(yè)面時(shí)是無(wú)法成功的,只能在瀏覽器地址欄輸入才能夠?qū)崿F(xiàn)重定向。下面我們來(lái)看看解決方法吧
    2019-06-06
  • JS中取二維數(shù)組中最大值的方法匯總

    JS中取二維數(shù)組中最大值的方法匯總

    本文通過(guò)三種解決方案給大家介紹js中取二維數(shù)組中最大值的方法。介紹的非常詳細(xì),具有參考價(jià)值
    2016-04-04
  • Bootstrap 模態(tài)框自定義點(diǎn)擊和關(guān)閉事件詳解

    Bootstrap 模態(tài)框自定義點(diǎn)擊和關(guān)閉事件詳解

    今天小編就為大家分享一篇Bootstrap 模態(tài)框自定義點(diǎn)擊和關(guān)閉事件詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • WEB前端實(shí)現(xiàn)裁剪上傳圖片功能

    WEB前端實(shí)現(xiàn)裁剪上傳圖片功能

    文件上傳功能在各大網(wǎng)站經(jīng)常會(huì)用到,今天小編通過(guò)本文給大家介紹了WEB前端實(shí)現(xiàn)裁剪上傳圖片功能的相關(guān)資料,需要的朋友可以參考下
    2016-10-10
  • echarts動(dòng)態(tài)渲染柱狀圖背景顏色及頂部數(shù)值方法詳解

    echarts動(dòng)態(tài)渲染柱狀圖背景顏色及頂部數(shù)值方法詳解

    在使用echarts時(shí),有時(shí)需要給柱狀圖設(shè)置背景,下面這篇文章主要給大家介紹了關(guān)于echarts動(dòng)態(tài)渲染柱狀圖背景顏色及頂部數(shù)值的相關(guān)資料,文中通過(guò)圖文以及代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-11-11
  • 幾個(gè)javascript操作word的參考代碼

    幾個(gè)javascript操作word的參考代碼

    幾個(gè)javascript操作word的參考代碼,對(duì)于具體的調(diào)用代碼,大家可以參考我們的上一篇文章。
    2009-10-10
  • Bootstrap table 定制提示語(yǔ)的加載過(guò)程

    Bootstrap table 定制提示語(yǔ)的加載過(guò)程

    bootstrap-table是在bootstrap-table的基礎(chǔ)上寫(xiě)出來(lái)的,專(zhuān)門(mén)用于顯示數(shù)據(jù)的表格插件。這篇文章主要介紹了Bootstrap table 定制提示語(yǔ),需要的朋友可以參考下
    2017-02-02
  • JavaScript實(shí)現(xiàn)獲取img的原始尺寸的方法詳解

    JavaScript實(shí)現(xiàn)獲取img的原始尺寸的方法詳解

    在微信小程序開(kāi)發(fā)時(shí),它的image標(biāo)簽有一個(gè)默認(rèn)高度,這樣你的圖片很可能出現(xiàn)被壓縮變形的情況,所以就需要獲取到圖片的原始尺寸對(duì)image的寬高設(shè)置,本文就來(lái)分享一下JavaScript實(shí)現(xiàn)獲取img的原始尺寸的方法吧
    2023-03-03
  • 一文詳解如何在uniapp中優(yōu)雅地使用WebView

    一文詳解如何在uniapp中優(yōu)雅地使用WebView

    最近工作中遇到webview,對(duì)于我這個(gè)剛接觸前端的小白來(lái)說(shuō)真的不懂啥意思,下面這篇文章主要給大家介紹了關(guān)于如何在uniapp中優(yōu)雅地使用WebView的相關(guān)資料,需要的朋友可以參考下
    2023-01-01
  • JavaScript利用Immerjs實(shí)現(xiàn)不可變數(shù)據(jù)

    JavaScript利用Immerjs實(shí)現(xiàn)不可變數(shù)據(jù)

    Immerjs?是一個(gè)用于管理?JavaScript?不可變數(shù)據(jù)結(jié)構(gòu)的庫(kù),它可以幫助我們更輕松地處理狀態(tài)的變化,并減少冗余代碼。本文就來(lái)帶大家揭秘如何利用Immerjs實(shí)現(xiàn)不可變數(shù)據(jù),感興趣的可以了解一下
    2023-04-04

最新評(píng)論