Reputation: 31
I've been reading about making AJAX calls to external API's and people say that you HAVE to use JSONP otherwise you will get a 404 error.
However I am able to calling the following API: http://www.telize.com/ip with the following code
$.ajax({
type: "GET",
url: "http://www.telize.com/geoip",
success: function(data) {
alert(data.ip);
$(".theTest").text(data.ip);
},
dataType: "JSON"
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
and it works for me perfectly.
This API is on an external server and I am able to get the data I want.
Am I missing something?
Upvotes: 0
Views: 337
Reputation: 7462
If you see in network console, it says response header value is = Access-Control-Allow-Origin:*
.
More info on Access-Control-Allow-Origin According to same origin policy, if you invoke API existing on other domain, there will be error , see this link. Browser will say it is CORS issue. To overcome this, API existing in other domain, has to allow you to invoke from your domain, i.e. just add the above header - help
That is why you are able to invoke this from any domain. Have a look on following screenshot.
Upvotes: 2