I have tried accessing url by the below method.The url consists of JSON data which needs to be parsed but got a Cross-Origin Request Blocked: error.
$.ajax({
type: "GET",
url: 'http://...',
async:true,
dataType : 'json',
crossDomain:true,
success: function(data, status, xhr) {
alert(data);
}
});
Then I tried to add JSONP to dataType for resolving cross origin request then got the following error - SyntaxError: unexpected token: ':'
The code snippet is given below -
$.ajax({
url: 'http://....',
dataType: 'JSONP',
jsonpCallback: 'callback',
type: 'GET',
success: function (data) {
alert(data);
}
})
The json to be accessed from url is of the form -
{"data":[{"name":"abc","age":24},{"name":"xyz","age":22}]}
I am a beginner.Please provide a solution regarding how to access the data in the url using jquery or javascript without the cross domain error and without using PHP. Any help would be appreciated.