1

I used XMLHttpRequest to GET page contents when user click on link from menu bar.

When I click on any link from menu bar, its throw bellow error. Also page is open but contents are not stay a while. It is automatically disappear after loading page.

[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.

function loadFile (id, fileURL){
 // get the element in HTML page
 var ele = document.getElementById (id);
 if (!ele){
  alert ("no id found to fill data!");
  return;
 }
 populateData (ele, fileURL);
}

// stream data of file "fileURL" into HTML element "ele"
function populateData (ele, fileURL){
 var req = false;
 if (window.XMLHttpRequest){
  try{
   req = new XMLHttpRequest ();
  }catch(E){
   req = false;
  }
 }else if (window.ActiveXObject){
  try{
   req = new ActiveXObject ("Msxml2.XMLHTTP");
  }catch(E){
   try{
    req = new ActiveXObject ("Microsoft.XMLHTTP");
   }catch(E){
    req = false;
   }
  }
 }// end of if
 
 // open the page whose content will be populated in the element
 if (req){
  try{
   req.open('GET', fileURL, false);
  }catch(E){
   alert ("error reading file!");
  }
  req.send (null);
  ele.innerHTML = req.responseText;
 }else{
  ele.innerHTML = "Your browser doesn't support loading file."
 }
}

0 Answers0