1 回答

TA貢獻1815條經驗 獲得超6個贊
在收到響應后重構代碼以進行同步。
var getGeoData = function (callback) {
$.ajax({
url: "https://geoip-db.com/jsonp",
jsonpCallback: "callback",
dataType: "jsonp",
success: callback
});
};
// Call the getGeoData function with callback
getGeoData(function (location) {
var cc = location.country_code;
var ncc = cc.toLowerCase();
sessionStorage.setItem('lastname', ncc);
$('#country_selector').attr('selected', true);
const countrySelectConfig = {
preferredCountries: ['pk', 'gb', 'us']
};
countrySelectConfig.preferredCountries.push(cc);
$("#country_selector").countrySelect(countrySelectConfig);
});
添加回答
舉報