Reputation: 97
I tried to answer all the questions related to this tag but I was not successful where is my mistake?
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://www.tcmb.gov.tr/kurlar/today.xml",
dataType: "xml",
headers: {
'Access-Control-Allow-Origin ': '*'
},
success: function (xml) {
alert("Success");
}
});
});
My error;
Access to XMLHttpRequest at 'http://www.tcmb.gov.tr/kurlar/today.xml' from origin 'http://localhost:44318' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I'm using jquery ajax in asp.net framework.please I tried the answers to all questions please do not throw the question title.
Upvotes: 0
Views: 492
Reputation: 8329
Try this:
$(document).ready(function() {
$.ajax({
type: "GET",
url: "https://cors-anywhere.herokuapp.com/http://www.tcmb.gov.tr/kurlar/today.xml",
dataType: "xml",
success: function(xml) {
console.log('success')
var xmlText = new XMLSerializer().serializeToString(xml);
var xmlTextNode = document.createTextNode(xmlText);
var parentDiv = document.getElementById('xml');
parentDiv.appendChild(xmlTextNode);
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="xml"></div>
Upvotes: 1