单击部分视图的链接时,Javascript运行时错误$ undefined

时间:2016-03-21 20:29:18

标签: jquery html5 partial-views pushstate

我正在使用路由javascript插件并遇到问题。当我点击链接加载部分页面时,我收到错误:

JavaScript运行时错误:' $'未定义

我尝试使用Path.js中的HTML5 pushState方法https://github.com/mtrpcic/pathjs

当我点击链接加载部分视图时,是否可以有人向我显示我弄乱了我的页面并丢失了对jQuery的引用?抛出错误的jQuery位于第一次正确加载的索引页面上。

看起来错误正在发生,因为我的索引页面正在重新加载,我认为在click事件中使用preventDefault()会阻止页面重新加载?

的index.html

<div id="mainContent"></div>

// All javascript files are located near the bottom of the index page
<script src="lib/jquery/jquery-1.11.2.min.js" type="text/javascript"></script>
<script src="lib/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="lib/jquery/jquery-ui.min.js" type="text/javascript"></script>
<script src="lib/page.js"></script>
<script src="lib/plugins/path.js" type="text/javascript"></script>
<script src="lib/engine.js" type="text/javascript"></script>

// This is in the bottom of my index.html page and runs correctly the first time, but clicking a link causes this     // to throw the error from above.
$(document).ready(function () {
    loadPrograms('data/programs.json');
});

home.html(部分页面 - 在初始页面加载时显示)

// Click a link to load a different partial page. Clicking this link will 
// cause the partial page to load and then the error happens.
<a href="#" target="_self" class="noprint lookup partialpageTest">

$(".partialpageTest").click(function (e) {
    var pathname = window.location.pathname;

    // Setting this URL causes the previously defined mapping in engine.js to fire
    window.location.href = pathname + "/mypartialpage";

    e.preventDefault();
});

的engine.js

// Sets up mapping that determines which page to load when a link is clicked.
// #mainContent is on the index page.
$(document).ready(function () {
    Path.map("/mypartialpage").to(function () {
       $("#mainContent").load("views/onepageprocess.html");
    }).enter();
});

0 个答案:

没有答案