I am trying to send an ajax request from my localhost development window to the server using
<!DOCTYPE html>
<html>
<head>
<title>JSSample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
var params = {
format: "JSON",
season: "2015REG"
};
$.ajax({
url: "https://<mysite>/sub/" + params.format + "/" + params.season,
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","<mykey>");
},
type: "GET"
})
.done(function(data) {
alert("success");
console.log("Data: \n" + JSON.stringify(data));
})
.fail(function(error) {
alert("error");
console.log("Error" + JSON.stringify(error));
});
});
</script>
</body>
</html>
when I look in firefox, I see that it actually sends an OPTIONS request - to which the server is not responding (404 not found), so I get an error with a request for cross-request.
OPTIONS
XHR
https://mysite [HTTP/1.1 404 Resource Not Found 2437ms]
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://mysite (Reason: CORS header 'Access-Control-Allow-Origin' missing).
What am I doing wrong? Why is jquery trying to set parameters when I explicitly send a GET? Also, I do not own this server, its another company that has a subscription API, so I cannot provide a key or anything else to help troubleshoot the problems.
source
share