根据链接ID将内容加载到DIV中

时间:2013-04-06 05:36:26

标签: jquery html load

基本上,我已经使用“链接”类创建了多个链接,并且每个链接都有一个代表它们的ID。

我编写了一个JQuery脚本,它对我不起作用,并抛出第一个错误:

    $(function() {
    $.get('pages/home.html')
    .success(function(response) {
        $('.contentblock').html(response);
    })
    .error(function(jqXHR, textStatus, errorThrown) {
        $('.contentblock').html('<h1>Failed to load page(s)!</h1>');
    });

    $(document).on('click', '.link', function() {
        $('.contentblock').html('<div class="animatedload"></div>');

        var page = 'pages/' + $(this).attr('id') + '.html';
        $('.contentblock').hide();
        $.get(page)
        .success(function(response) {
            $('.contentblock').html(response);
        })
        .error(function(jqXHR, textStatus, errorThrown) {
        });
        $('.contentblock').fadeIn(1000);
    });
});

它在第6行抛出.error(function()){}。

请帮我解决这个问题:(提前感谢您的帮助!

编辑:是服务器问题,而不是代码:)

〜MCD

1 个答案:

答案 0 :(得分:0)

原来@crimson_penguin是对的!

出于安全原因,它无法正常工作,因此请将其放在服务器上以使其正常工作