I Got Following Error While Calling API From AJAX Jquery.
Access to XMLHttpRequest at '' from origin 'http://localhost:8191' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
I don't have Access To Change API Coding. I just have API call From javascript or Jquery. I used Following Code For Calling REST API.But I is not Working.
$.ajax({
url: '',
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type':'application/json'
},
method: 'GET',
dataType: 'json',
data: '',
success: function(data){
console.log('succes: '+data);
}
});
I Got Following Error While Calling API From AJAX Jquery.
Access to XMLHttpRequest at 'https://www.demo.in/rest/employee/mapping/v3/9714620362' from origin 'http://localhost:8191' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
I don't have Access To Change API Coding. I just have API call From javascript or Jquery. I used Following Code For Calling REST API.But I is not Working.
$.ajax({
url: 'https://www.demo.in/rest/employee/mapping/v3/9714620362',
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type':'application/json'
},
method: 'GET',
dataType: 'json',
data: '',
success: function(data){
console.log('succes: '+data);
}
});
Share
Improve this question
edited Nov 26, 2018 at 7:23
Rajesh Pandya
1,5504 gold badges21 silver badges32 bronze badges
asked Nov 26, 2018 at 7:03
ReemaReema
612 gold badges2 silver badges3 bronze badges
1 Answer
Reset to default 3Update the dataType to "jsonp" and it should work
$.ajax({
url: 'https://www.demo.in/rest/employee/mapping/v3/9714620362',
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type':'application/json'
},
method: 'GET',
dataType: 'jsonp',
data: '',
success: function(data){
console.log('succes: '+data);
}
});