tuscan88
tuscan88

Reputation: 5829

Weird issue with different types of page loads with jquery dropkick plugin

I am using a jQuery plugin called dropkick to make my select boxes look nicer.

On page load I do an ajax request to retrieve data from my database and populate the form with it.

Once I have populated this form I call $.dropkick('reset'); which will update the dropkick elements to represent the form data.

This works fine if I do a page refresh with F5 but if I do a refresh by going to the url bar and hitting enter, so a new page load effectively I get an error saying $.dropkick isnt a function. So it's as if the dropkick plugin hasn't been loaded at that point.

The thing is though by the time the ajax request comes backSeems very strange how it works after a refresh but not a new page load.

The script tag to load the plugin is above all of the ajax code in the dom and I am using firefox 19.0.1

Upvotes: 1

Views: 469

Answers (1)

MackieeE
MackieeE

Reputation: 11872

You could check if dropkick is defined before calling it by using typeof, if not - collect it via $.getScript which would load it for use within the callback,

$(document).ready(function() {
    if ( typeof dropkick == "undefined" ) {
      $.getScript("js/dropkick.js", function(){
         $.dropkick('reset');  
         //.. More code
      });
    } 
});

Upvotes: 1

Related Questions