Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 根据链接id将内容加载到DIV中_Jquery_Html_Load - Fatal编程技术网

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

Jquery 根据链接id将内容加载到DIV中,jquery,html,load,Jquery,Html,Load,基本上,我已经用“link”类创建了多个链接,每个链接都有一个它们所代表的id 我编写了一个JQuery脚本,它对我不起作用,并抛出了第一个错误: $(function() { $.get('pages/home.html') .success(function(response) { $('.contentblock').html(response); }) .error(function(jqXHR, textStatus, error

基本上,我已经用“link”类创建了多个链接,每个链接都有一个它们所代表的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);
    });
});
$(函数(){
$.get('pages/home.html')
.成功(功能(响应){
$('.contentblock').html(响应);
})
.error(函数(jqXHR、textStatus、errorshown){
$('.contentblock').html('加载页面失败!');
});
$(文档).on('单击','.link',函数(){
$('.contentblock').html('');
var page='pages/'+$(this.attr('id')+'.html';
$('.contentblock').hide();
$.get(第页)
.成功(功能(响应){
$('.contentblock').html(响应);
})
.error(函数(jqXHR、textStatus、errorshown){
});
$('.contentblock').fadeIn(1000);
});
});
它在第6行抛出.error(function()){}

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

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


~MCD

原来@crimson_penguin是对的


出于安全原因,它不会工作,所以将它放在服务器上让它工作

该错误只与初始加载有关,而不是与单击的加载有关,对吗?另外,我很确定您指定的success/load函数是错误的,但是我必须检查一下。啊,没关系,我只是没有看到指定处理函数的那种形式。在任何情况下,为什么不在输出中包含textStatus和errorThrown来帮助调试呢?如果不知道它为什么会出现错误函数,就很难说它为什么不起作用。它以前在@crimson_penguin上起作用,但现在似乎不起作用了,它的代码是一样的:sDid你是否按照我的建议去做以找出错误是什么?在不知道错误是什么的情况下,我们无法真正理解错误发生的原因。您是从一个文件运行它,请求另一个本地文件吗?如果是这样的话,出于安全原因,那是行不通的。是的,出于安全原因,那是行不通的。如果它真的起作用,那么如果你从互联网上保存了一些网页,然后在本地打开,它就可以访问你可能不想要的所有文件。把它放在服务器上,它应该可以工作。