Custom Script to Return Remote IP

Can someone help me with this script? The IP address will be displayed in the ip_logged_in field but i somehow I will not be able to save the document. (e.g. i click on save, and nothing happens)

cur_frm.cscript.punch_in = function(doc) {
$.getJSON("https://api.ipify.org?format=jsonp&callback=?",
      function(json) {
	doc.ip_logged_in = json.ip;
	refresh_field("ip_logged_in");
      });
	doc.time_in = new Date();
	refresh_field("time_in");

}

Check your JS console, there must be some error