here is the code
$(function() {
$("input[type=button]").click(
function(evt) {
if( !window.sayHi ) {
evt.target.disabled = "disabled";
$.getScript("hi.js", function() {
sayHi($("input[type=text").val());
evt.target.disabled = "";
});
}
else{
sayHi( $("input[type=text").val() );
}
});
});
what will happen if i click on button repeatedly then $.getScript() will download hi.js file repeatedly or only first time?
$.getScript() check the js file exist in client machine or not….if not then it download only? please discuss. thanks
i got the detail about getScript() function. here i am giving the code where i stuck for few lines.
jQuery.cachedScript = function(url, options) {
// allow user to set any option except for dataType, cache, and url
options = $.extend(options || {}, {
dataType: "script",
cache: true,
url: url
});
// Use $.ajax() since it is more flexible than $.getScript
// Return the jqXHR object so we can chain callbacks
return jQuery.ajax(options);
};
// Usage
$.cachedScript("ajax/test.js").done(function(script, textStatus) {
console.log( textStatus );
});
1) cachedScript() function need two argument but only one is sending at the time of calling….why?
2) from where done() function come here?
please explain the above two points
jQuery appends the current Unix epoch as a GET param so it will be downloaded for each
clickevent (provided they don’t occur in the same millisecond) :P.Source.
It’d be good form to set a flag and test for it or look for a variable that is defined in the new script. Then write a condition based on that.