I am trying to make an AJAX request to get information of a restAPI.
If I test it with POSTMAN, it works and with Putty too with this code selecting RAW, but not with AJAX due to CORS issues.
This is the code that works on Putty (it returns JSON data):
GET /api/slot/0/io/do HTTP/1.1\r\n
Host: 172.25.0.208\r\n
Content-Type: application/json\r\n
Accept: vdn.dac.v1\r\n
\r\n
This is the jQuery AJAX code:
//Build GET Request URL
var url = "//" + ipDevice + "/api/slot/" + slot + "/io/do";
jQuery.support.cors = true;
//GET Request with HTTP header info
$.ajax({
"url": url,
"method": "GET",
"headers": {
"Accept": "vdn.dac.v1",
"Content-type": "application/json"
},
"success": function (response) {
getPowerStatusSuccess(response);
},
"error": function (response) {
getPowerStatusFail(response);
}
});
The error I got on browser console (Firefox) is: