JS Judge City by IP address

Source: Internet
Author: User
Tags add time getscript

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.