1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <html lang="fr">
<head>
<meta charset="utf-8">
<title>jQuery.getScript demo</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<script>
jQuery.cachedScript = function( urli, options ) {
// Allow user to set any option except for dataType, cache, and url
options = $.extend( options || {}, {
dataType: "script",
cache: true,
url: urli
});
// Use $.ajax() since it is more flexible than $.getScript
// Return the jqXHR object so we can chain callbacks
return jQuery.ajax( options );
};
url="myload.js";
// Usage
$.cachedScript( url ).done(function( script, textStatus ) {
document.write("chargement 1:"+loadvar())
});
document.write("chargement 2:"+ loadvar())
</script>
<script>
document.write("chargement 3:"+ loadvar())
</script>
</body>
</html> |
Partager