简体   繁体   English

转到另一页后,jQuery加载未加载

[英]Jquery Load Not Loading after going to another page

I have an html page where a JQuery Loads a page into a div on click. 我有一个HTML页面,其中JQuery在单击时将页面加载到div中。 I can click on it and it goes to page 2 and it works. 我可以单击它,然后转到第2页,它可以工作。 I have the same link that goes back to page 1 and it will load the html in page 1, but if I click back to page 2 it will not load. 我有回到第1页的相同链接,它将在第1页中加载html,但是如果我单击回到第2页,则将不会加载。 So pretty much I cannot go back and forth on loading a div from Jquery. 因此,我几乎无法从Jquery加载div来回切换。 I have search and seen something on using live() but can't seem to get anything to work. 我已经搜索过,并且在使用live()时看到了一些东西,但是似乎什么也无法工作。 Any Suggestions? 有什么建议么?

My Jquery Function to load the div from another page. 我的Jquery函数从另一个页面加载div。

<script>
function changepage(page) {
    $(function(){
        $('#maincontent').load('index.php?p='+page);
        return false;
    });
}
</script>

HTML To load the page 2: HTML要加载页面2:

<a href="#" onclick="changepage('page2');">Page 2</a>

HTML To load back to page 2 HTML加载回第2页

<a href="#" onclick="changepage('page1');">Page 1</a>

EDIT: Entire Page: 编辑:整个页面:

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>My Page</title>


</head>

<body>
<div id="wrapper">
        <!-- Page Content -->
        <div id="page-wrapper">
            <div class="container-fluid">
            <div id="maincontent">

            <a href="#" onclick="changepage('page2');">Page 2</a>


                </div>
                <!-- /.maincontent -->
            </div>
            <!-- /.container-fluid -->
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->


<script>
function changepage(page) {
    $(function(){
        $('#maincontent').load('subpage.php?p='+page);
        return false;
    });
}
</script>

</body>

</html>

jQuery是否链接到该页面?

I could be wrong, but I don't think you've given us enough information here. 我可能是错的,但我认为您在这里没有给我们足够的信息。 The above code looks fine. 上面的代码看起来不错。 Is input.php working correctly? input.php是否正常工作? What happens when you call: 致电时会发生什么:

http://[domain]/index.php?p=page1
http://[domain]/index.php?p=page2

From a browser? 从浏览器? Does it output a whole page, or just #maincontent? 它输出整个页面还是仅输出#maincontent? It's kind of weird, does the index page output a single div, or are you stuffing a whole html page inside another one? 有点奇怪,索引页面输出的是单个div,还是您将整个HTML页面填充到了另一个页面中? Sound like it could be the output from index.php, which would normally be the landing page of your site, so why are you stuffing the whole landing page inside a div? 听起来好像是index.php的输出,通常这是您网站的登录页面,所以为什么要将整个登录页面填充到div中?

I agree with tokyovariable . 我同意东京变量 you need to link jquery before using it in function. 您需要先在功能中使用jQuery,然后再链接它。 Try adding 尝试添加
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script> before script with changepage function. <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>之前具有changepage功能的脚本。
Also make sure jquery is loaded before changepage function is called. 还要确保在调用changepage函数之前已加载jquery。 Try 尝试
function changepage(page) { $(document).ready(function(){ $('#maincontent').load('index.php?p='+page); return false; }); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM