All the answers that I've read so far were about making a xhr request, but that never works, because it gets blocked by the browser.
I've tried the following:
$.ajax({
url: "https://www.fly.faa.gov/flyfaa/usmap.jsp",
type:"POST",
data:"data",
contentType:"application/json; charset=utf-8",
dataType:"json",
success: function(){
alert("WORKS")
}
})
and
$.getJSON("https://www.fly.faa.gov/flyfaa/usmap.jsp", function(data) {
alert(data)
})
also,
$.get("https://www.fly.faa.gov/flyfaa/usmap.jsp", function(data) {
alert(data)
})
They all return an error saying that the request is blocked, because ..Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
In the book that I'm reading, the example they gave for getting a JSON string and using it for a Chrome extension is the following:
$(document).ready(function() {
$("#btn").click(function() {
$("#info").html("Getting information...");
var code = $("#airportcode").val();
$.get("http://services.faa.gov/airport/status" + code + "?format=application/json", "", function(data) {
displaydata(data);
})
})
})
This isn't making a xhr request, right? I wanna take the JSON string from the same website, but it's not working, it keeps returning the above mentioned error.
I even tried it as an extension, and edited the manifest
file to permit the website, but the result was the same.
What am I doing wrong?