你如何使用Ajax使用Ajax加载的内容中的链接加载其他页面 [英] How do you load another page with ajax with a link within ajax loaded content

查看:72
本文介绍了你如何使用Ajax使用Ajax加载的内容中的链接加载其他页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了装载有阿贾克斯,目前的水平菜单上的权利和需要它在内容方面,而不是几级。我不知道如何有AJAX加载的内容中的单击事件加载在它自己的内容的div另一个层次。德code我正与在这里:

I am building a few levels that are loaded with ajax and currently the level menu is on the right and need it to be in the content area instead. I'm not sure how to have a click event within the ajax loaded content load another level in it's own content div. Teh code I'm working with is here:

var $level = $('#navigation a'),// Links on the right
    last = null;// Last Level

$level.click(function(){
    if( last != this ){ // let's avoid needless requests
        var url = 'html/' + this.hash.slice(1) + '.html';
        $('#content').html( '<p class="loading">Loading...</p>' ).load( url, function(){
            this.scrollLeft = 0;//scroll back to the left
        });
    }
    last = this;
    this.blur(); // Remove the awful outline
    return false;
});

$level.eq(0).click(); // Load the first Level

最终的目标是让用户能够挖掘的内容区域内的图像(这是AJAX加载),以在该级别导航,或装入另一个层面(的.html页面)。我试图避免的是有申报脚本中每个级别的每个实例一样会有超过5。

The end goal is to have the user be able to tap on images within the content area (that's ajax loaded) to navigate within that level, or to load another level (.html page). What I'm trying to avoid is to have to declare every instance of every level within the script as there will be more than 5.

我的测试环境是在这里: http://www.beingproperties.com/test/jscroll -ajax /

my test environment is here: http://www.beingproperties.com/test/jscroll-ajax/

任何帮助将是AP preciated。谢谢!克里斯

Any help would be appreciated. Thanks! -Chris

推荐答案

您应该改变你的code绑定到click事件,直接使用实时绑定。

You should change your code from binding to the click event directly to use the live-binding.

$level.click(function() {

您应该使用这样的:

$level.live('click', function() {

如果你正在使用jQuery 1.7+正确的语法是:

If you are using jQuery 1.7+ the correct syntax would be:

$('#navigation').on('click', 'a', function() { 

这篇关于你如何使用Ajax使用Ajax加载的内容中的链接加载其他页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆