Skip to content

Instantly share code, notes, and snippets.

@crazyyy
Last active January 5, 2019 17:58
Show Gist options
  • Save crazyyy/9859953dab5aef4082c8165bd0edc114 to your computer and use it in GitHub Desktop.
Save crazyyy/9859953dab5aef4082c8165bd0edc114 to your computer and use it in GitHub Desktop.
#js || callback functon example
/* 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