Call to api does not work
AnsweredHi, I'm making this api call and not getting any results. When I make the call from the browser and search with that imo, I get back the vessel information but not in the call from code.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="pr"></div>
<script>
var vessel;
getInfoVessel("9146314");
function httpGetAsync(url, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
callback(xmlHttp.responseText);
}
}
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function getInfoVessel(IMO){
httpGetAsync('http://services.marinetraffic.com/api/exportvessel/v:5/7[key]/protocol:jsono/imo:9146314', function(response) {
vessel = JSON.parse(response)[0];
document.getElementById('pr').innerHTML = vessel.MMSI;
});
}
</script>
</body>
</html>
-
Official comment
Hello Ismael,
I was just informed that our development team has enabled cross-origin HTTP requests on our servers.
Therefore, normally, with the above call, you should be able to receive data.
For any further inquiry, please do not hesitate to let me know.Best regards,
Comment actions -
Dear Ismael,
Thank you for reaching out to us.
I have escalted your request to our API support team.
One of my dear colleagues will be contacting you as soon as possible to help you in this matter.
Should you need anything else in the meantime, I hope that you will not hesitate to let me know.
I will be happy to assist.
Kind regards,
-
Hello Ismael,
As you correctly mention in your e-mail, the reason for not receiving any data is the cross domain policy.
Unfortunately, we have no available code snippets at the moment which might help you in your implementation.
In order to receive the response, you need to use some sort of third party agent that can get the data for you. The two most common ways of doing this are to either make a request of your own server to get some content from some other server. This will allow your server to fetch the data from the other server and return it to you, or use a proxy server with the same results as described above.
Hope the above helps.
Best regards,
Please sign in to leave a comment.
Comments
4 comments