user3763124 user3763124 - 3 months ago 9
HTML Question

Getting \n returned in jquery and not sure why

I created a site a month ago at work and there is a section where I get the user's IP address and current location and display it. It was working fine up until I went on the website today and the location part is no longer working.

The IP returns the proper IP but for the location returns: \n

This is what i see:

Detected IP Address: the correct IP

Location: \n, \n (instead of city, state)

I asked the few people at work who have access to the code and they all told me they never touched anything.

Anyone know what happened, that can just cause code to seemingly just stop working overnight?

HTML

<div class="warning-info">
Detected IP address: <span class="yellow" id="ip"></span><br>
Location: <span class="yellow" id="address"></span><br><br>
</div>


Jquery code

$.get("http://ipinfo.io", function (response) {
$("#ip").html(response.ip);
$("#address").html(response.city + ", " + response.region);
}, "jsonp");

Answer

On the site page, they recommend to use $getJSON, you can try the following:

$(function(){
    $.getJSON('http://ipinfo.io', function(data){
      $("#ip").html(data.ip);
      $("#address").html(data.city + ", " + data.region);
    });
});

This piece of code is working on my local environment(Apache+PHP)