I am trying to retrieve data from webpage that returns data in JSON format.I am using simple ajax Jquery to do the the same
$(document).ready(function() {
/*Project Db start Here*/
$.ajax({
url: 'http://enlytica.com/RSLivee/EnClient',
type: 'GET',
dataType: "JSONP",
crossDomain: true,
success: function(data) {
//called when successful
alert("success");
},
error: function(e) {
//called when there is an error
//console.log(e);
alert(e);
}
});
});
But i am getting the following error in my html page:
XMLHttpRequest cannot load http://local.html.
No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'null' is therefore not allowed access.
How could i possible fix this and get the data from the link. Thanks in Advance
You wont be able to send a request to that link since it is located on a different domain.
As the page and the target URL are at different domains, your code is actually attempting to make a Cross-domain (CORS) request and not an ordinary GET or POST request.
The same-origin policy will allow the browsers to make ajax calls to services in the same domain.
The file which serves your request must send this header
Access-Control-Allow-Origin: *
If this header is not sent by the file from the server, the browser will just not be able to do anything.
Check out the link how you can enable the CORS request