0

I need to get the html source of a page from javascript, without jQuery

In my object, I did this :

showPopUp: function() {

    //Call method to get Html Src
    BLExitIntent.getPageSrc();
    alert(BLExitIntent.pageContent);

},
getPageSrc: function(){
    var request = new XMLHttpRequest();
    request.open('GET', 'page.html', false);
    request.onreadystatechange = function() {
      if (this.readyState === 4) {
        if (this.status >= 200 && this.status < 400) {
          // Success!
          BLExitIntent.pageContent = this.responseText;
        } else {
          console.log('Page' +  'page.html' + ' not found');
        }
      }
    };      
    request.send();
    request = null;
},

My problem is : when I make a synchronous request, the

alert(BLExitIntent.pageContent);

give the good result but I have the warning about User Experience :

Synchronous XMLHttpRequest outside of workers is in the process of being removed from the web platform as it has detrimental effects to the end user's experience.

But, if I make the same call in an asynchronous way, "BLExitIntent.pageContent" is empty

If there a way to do it?

My call is get the Htlm code of an external page...

Portekoi
  • 1,087
  • 2
  • 22
  • 44
  • You have to work around the asynchronous nature of ajax, and how you'd do that is thoroughly explained in the duplicate linked at the top of your question. – adeneo Jun 29 '15 at 09:30
  • 1
    Take a look at the following question http://stackoverflow.com/questions/30008114/how-do-i-promisify-native-xhr – DavidDomain Jun 29 '15 at 09:35

0 Answers0