1 var province = ' ; 2 var city = ' ; 3 jquery.getscript ("Http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js",function () {4 province = remote_ip_info["province"]; 5 City = remote_ip_info["City"]; 6 alert (city)7
jQuery.getScript()
function is used to load a JavaScript file in HTTP Get form and run it .
This function is used to dynamically load the JS file and execute the JS code in the file at the global scope.
This function can load a cross-domain JS file. Note that the function is loading data asynchronously .
The function belongs to the global jQuery
object.
Note : If you load the JS file of the same URL multiple times, even if the server is caching the JS file, the JS file jQuery.getScript()
will not be cached the second time or later. Because the function will add a timestamp parameter suffix after the URL of the JS file, which avoids the browser getting the cached JS file.
Load and execute JS file: http://www.365mini.com/static/js/jquery-util.js
$. getScript( "Http://www.365mini.com/static/js/jquery-util.js" );
The second time to load and execute the JS file: http://www.365mini.com/static/js/jquery-util.js
$. getScript( "Http://www.365mini.com/static/js/jquery-util.js" );
GetScript () will add time stamp to avoid JS cache
Also, be careful not to jQuery.getScript()
invoke the variable or function directly in the JS file directly after execution, because jQuery.getScript()
it is loaded asynchronously , and when you access a variable or function in it, it is possible that the JS file has not been fully loaded.
It is advisable to success
handle the callback function, or you can confirm that the JS file is now loaded.
JS Judge City by IP address