简体   繁体   English

不确定为什么此JQuery代码不起作用

[英]Unsure why this JQuery code won't work

This works inside my script section in a Jade file: 这在Jade文件中的脚本部分中起作用:

$('#viewUsersTbl').dataTable({
                        "sScrollY": "200px",
                        "bPaginate": false
                    });

This also works inside the same script section: 这也可以在同一脚本部分中使用:

$.get('/showUsers', function(){

});

When I do this, why would the code inside the .get callback not work? 当我这样做时,为什么.get回调中的代码不起作用?

$.get('/showUsers', function(){
                     $('#viewUsersTbl').dataTable({
                        "sScrollY": "200px",
                        "bPaginate": false
                    })
                });

you might setup some error handling callback methods. 您可能会设置一些错误处理回调方法。 I'm not a fan from jquery get and prefer $.ajax. 我不是jquery get的粉丝,更喜欢$ .ajax。 The best way to use jqueries callback methods is by chaining them. 使用jqueries回调方法的最佳方法是链接它们。

$.ajax({
    url: '/path/to/file',
    type: 'GET',
    dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
    data: {param1: 'value1'},
})
.done(function() {
    console.log("success");
})
.fail(function() {
    console.log("error");
})
.always(function() {
    console.log("complete");
});

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

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