I have asked an earlier question here (Synchronous XMLHttpRequest issue) but it was closed due to "duplicate". I have tested the duplicate answer and it does not solve the issue.
Issue
I am trying to read XML data and I am receiving warning - Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.
, upon the duplicate answer posted (How to get the response of XMLHttpRequest?), which provides solution that I must change the xml.open() from "false" to "true" in order to stop the warning from happening.
I did that and yes it solved the problem of not receiving any warning message but I can no longer receive any XML data. I have tested with xml.responseText
and I receive empty response. So what is causing this issue and how do I solve this without using AJAX (most of the online answers have AJAX implemented in them).
<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;
}
</script>
<?xml version = "1.0" ?>
<List>
<PDF>
<id>1</id>
<link>myPDF.pdf</link>
</PDF>
</List>
</xml>