I am trying to read XML data and I am receiving an error such as Synchronous XMLHttpRequest on the main thread is deprecated...
. I have searched online and got to know that I must put the async to true but still it does not solve the issue. I am still not able to read the data. How to solve this?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
</head>
</html>
<script>
var xml = new XMLHttpRequest();
xml.onreadystatechange = function() {
if (xml.readyState == XMLHttpRequest.DONE) {
}
}
xml.open('GET', 'PDF_List.xml', false);
xml.send(null);
var xmlData = xml.responseXML;
if(!xmlData){
xmlData = (new DOMParser()).parseFromString(xml.responseText, 'text/xml');
var PDF = xmlData.getElementsByTagName("PDF");
var link = PDF[0].getElementsByTagName("link")[0].firstChild.data;
console.log(link);
}
</script>
<?xml version = "1.0" ?>
<List>
<PDF>
<id>1</id>
<link>myPDF.pdf</link>
</PDF>
</List>
EDIT:
After referring to the duplicate link posted above, the solution given was to add "true" in xml.open() so that no async request is waiting to be received. But if I change it to true, I no longer receive the warning but then I am not able to receive any data from XML. I have tested it and it shows empty value under xml.responseText
. I have even updated my code above. How do I remove this warning?