Hi there,
I am very new to JS so please bare with me. I am wanting to use promises in order to retrieve information from a JSONP request. Ive requested the country code however it appears to not be working. Ive done an if statement to ask if myFunction2 does not equal GB to show a random picture. However this field from this JSON request DOES equal GB.
Could someone please advise where to look to correct this issue pleaseCode:<script> var promise = new Promise(function(resolve, reject) { // do a thing, possibly async, then… function myFunction2(){ $.ajax({ url: '//freegeoip.net/json/', type: 'POST', dataType: 'jsonp', success: function (location) { myipaddress = location.country_code; return location.country_code; } }) }; if (myFunction2 !== "GB") { resolve("Stuff worked"); } else { reject(new Error("It broke")); } }); promise .then(result => console.log(result)) .catch(error => { fallbackimg = new Image(); fallbackimg.src = "https://i.stack.imgur.com/N6iem.png?s=64&g=1"; fallbackimg.alt =""; document.getElementById("demo").appendChild(fallbackimg); }); </script>
Thankyou
Rustic




Reply With Quote

