/******************************************************************************
PROGRAM FLOW:
JS finds element with data-ip attribute (served up by PHP)
JS makes AJAX call with IP address and receives true/false from IP lookup
JS then hide content based off class or id.
*****************************************************************************/
var FIPS = {
US: {
name: 'United States',
sampleIp: '209.68.11.55',
imageCoords: {
x: '-440',
y: '-150'
}
},
JP: {
name: 'Japan',
sampleIp: '1.1.90.82',
imageCoords: {
x: '-490',
y: '-52'
}
},
GB: {
name: 'Great Britain',
sampleIp: '5.11.16.3',
imageCoords: {
x: '-343',
y: '-150'
}
}
};
var testCountry = FIPS['JP'];
// this would be served up by PHP
$('#dataCtr').attr('data-ip', testCountry.sampleIp);
/*
$.each(FIPS, function (a, b) {
$('#fipsList').append('<li class="fips"id="' + a + '">' + a + ' ' + b + '</li>');
});
*/
//alert('IP-based Geolocation Content Display\n\nPHP serves up visitor IP address.\n JS uses this to determine which elements will be shown/hidden.\n\nClick "Start" to simulate this. ')
$('#start').on('click', function () {
/* AJAX ERROR debugging setup */
$.ajaxSetup({
error: function (jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.