简体   繁体   English

我的页面不会使用Ajax动态加载

[英]My page won't dynamically load using ajax

I am trying to dynamically change the content of my #nonMobileDiv in index. 我正在尝试动态更改索引中#nonMobileDiv的内容。

Here's a part of my index.php: 这是我的index.php的一部分:

<div class = "tiles">
    <a href="CreateNotebook.php" id="createNew">
    <img src="images/addSign.png" alt="Nature">
        <div class="titleMask">
           <h2>Create Notebook</h2>
        </div>
        <div class = "mask">
           <p>Create your own Notebook</p>
        </div>
    </a>
</div>

Here's my function: 这是我的功能:

 $('.tiles').on('click', 'a', function (e) {
        e.preventDefault();

        var url = $(this).attr('href');

        $.ajax({
            type: 'GET',
            url: url,
            success: function (data) {
            $('#nonMobileDiv').html(data); 
        }

        });

    });

I am wondering why it redirects to CreateNotebook.php even though I used the e.preventDefault(). 我想知道为什么即使我使用e.preventDefault(),它也重定向到CreateNotebook.php。 I would love to hear any ideas. 我很想听听任何想法。

Thanks. 谢谢。

感谢您的所有评论和建议,显然我在$('.tiles').on('click', 'a', function (e) {之前写了一个开放式(不完整,我认为写得不好)函数导致问题。

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

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