zoukankan      html  css  js  c++  java
  • history.js 一个无刷新就可改变浏览器栏地址的插件(不依赖jquery)

    解决:

      不刷新改变网址地址

    github地址

    简介

    Doc

    示例:

         function onRequestSuccess() {
                if (currentRequestUrl) {
                    inRequestState = true;
                    var currentMenuName = $(".submenu li.current").text().trim();
                    currentRequestUrl = currentRequestUrl.replace("&X-Requested-With=XMLHttpRequest", "");
                    History.pushState({ activeMenu: currentMenuName, title: "@ViewBag.Title", url: currentRequestUrl }, $("#wrap").find("title").text(), currentRequestUrl);
                }
            }
    
            History.Adapter.bind(window, 'statechange', function () { // Note: We are using statechange instead of popstate
                if (inRequestState) {
                    inRequestState = false;
                    return;
                }
                var state = History.getState(); // Note: We are using History.getState() instead of event.state
                if (state) {
                    document.title = state.title;
                    var mn = state.data.activeMenu;
                    $.ajax({
                        type: "POST",
                        url: state.url,
                        success: function (data) {
                            $("#wrap").html(data);
                            switchMenu(mn);
                        },
                        failure: function (errMsg) {
                            $("#wrap").html("<p>服务器繁忙,请稍后再试.</p>");
                            console.log(errMsg);
                        }
                    });
    
                }
            });    
    

      

  • 相关阅读:
    React 构建方法总结
    集思广益 (一)
    C#方法调用
    C# Hello World 实例
    C# 环境
    C# 简介
    对象类型的本地写入---plist文件创建以及读取
    正则判断 手机邮箱的正确格式
    数组去重
    Base64编码
  • 原文地址:https://www.cnblogs.com/panpanwelcome/p/7682976.html
Copyright © 2011-2022 走看看