TSCAmerica.com
TSCAmerica.com

Reputation: 5377

Ajax to Read page content ( Same domain )

I am using following JavaScript/Ajax to read page content, This script works great but it loads only Half of the page contents of shoppingcart.asp, I want the shoppingcart.asp to load fully and then show all webpage contents, is this possible, shall I add a delay?

<script language="Javascript">

  var anUrl = "http://www.abc.com/shoppingcart.asp";
  var myRequest = new XMLHttpRequest();

  callAjax(anUrl);

  function callAjax(url) {
     myRequest.open("GET", url, true);
     myRequest.onreadystatechange = responseAjax;
                 myRequest.setRequestHeader("Cache-Control", "no-cache");
     myRequest.send(null);
  }

  function responseAjax() {
     if(myRequest.readyState == 4) {
        if(myRequest.status == 200) {
            result = myRequest.responseText;
            alert(result);
            alert("we made it");
        } else {
            alert( " An error has occurred: " + myRequest.statusText);
        }
     }
  }

</script>

Upvotes: 1

Views: 602

Answers (1)

SomeKittens
SomeKittens

Reputation: 39522

JavaScript's alert() has a maximum amount of text that it can contain. If you want to check large amounts of text, there are two options:

  1. You can log it in the browser's console using console.log(text)
  2. You can put it into a div using document.getElementById("divID").innerHTML = text

Upvotes: 1

Related Questions