gjw80
gjw80

Reputation: 1078

Unsure why this JQuery code won't work

This works inside my script section in a Jade file:

$('#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('/showUsers', function(){
                     $('#viewUsersTbl').dataTable({
                        "sScrollY": "200px",
                        "bPaginate": false
                    })
                });

Upvotes: 0

Views: 72

Answers (1)

kasper Taeymans
kasper Taeymans

Reputation: 7026

you might setup some error handling callback methods. I'm not a fan from jquery get and prefer $.ajax. The best way to use jqueries callback methods is by chaining them.

$.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");
});

Upvotes: 1

Related Questions