Last active
January 5, 2019 17:58
-
-
Save crazyyy/9859953dab5aef4082c8165bd0edc114 to your computer and use it in GitHub Desktop.
#js || callback functon example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* first */ | |
JApp.GetUserIP(function(sIP) { | |
oUserIp.val(sIP); | |
}); | |
/* second */ | |
that.GetUserIP = function(fnCallback) { | |
var sDefault = "N/A"; | |
$.ajax({ | |
type: 'POST', | |
url: '//api.userinfo.io/userinfos', | |
success: function(sResponse) { | |
var oResp = jQuery.parseJSON(sResponse); | |
console.log(sResponse) | |
if (oResp.ip_address != 'undefined') { | |
fnCallback(oResp.ip_address); | |
} else { | |
fnCallback(sDefault); | |
} | |
}, | |
error: function() { | |
fnCallback(sDefault); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment