How can I load a JavaScript with this code
<script type="text/javascript" src="http://uads.ir/l.php?s=125125&w=5307cd5c027373e1773c9869"></script>
after page has loaded
$(document).ready(function()
{
});
Is there another way?
Try appending the script to the head section: (Working jsFiddle)
$(document).ready(function(){
$('<script/>',{type:'text/javascript', src:'http://uads.ir/l.php?s=125125&w=5307cd5c027373e1773c9869'}).appendTo('head');
});
EDIT: I like this syntax better..
I prefer to create the script tag, then its type and src attribs like this:
var fileref=document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", filename);
Straightforward and semantic.
By using the ajax() function as follows:
$(document).ready(function() {
$.ajax({
url: "http://uads.ir/l.php?s=125125&w=5307cd5c027373e1773c9869",
dataType: "script",
cache: true
});
});
You can use jQuery's getScript()
method to achieve this. Documentation here. Usage:
$.getScript( "ajax/test.js", function( data, textStatus, jqxhr ) {
console.log( data ); // Data returned
console.log( textStatus ); // Success
console.log( jqxhr.status ); // 200
console.log( "Load was performed." );
});