How to call to one page from another, without reloading.

Discussion in 'JavaScript' started by Arson, Jun 24, 2007.

  1. #1
    Im trying to make a javascript that calls to a page without actually opening it.

    Sort of like fopen() in php.

    I have it so it counts down from 10 seconds, and when it hits 0, I want it to call the other page without reloading.

    iknow location.href works, but that loads the script into their browser.

    Can anyone help?
     
    Arson, Jun 24, 2007 IP
  2. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #2
    I would use ajax. All you need to do is:

    function getHTTPObject() {
    if (typeof XMLHttpRequest != 'undefined') {
    return new XMLHttpRequest();
    }
    try {
    return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    return new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
    }
    return false;
    }

    var http = getHTTPObject();


    function handleHttpResponse() {
    if (http.readyState == 4) {
    var temp = http.responseText;
    // do whatever you want with the code here...
    }
    }


    function LoadPage(){
    var url = "LoadedPageURL.html";
    http.open("GET", url, true);

    http.onreadystatechange = handleHttpResponse;

    http.send(null);
    }


    So when your counter reaches zero, call LoadPage(). The response text you'll get in handleHttpResponse() is the code of the page you want to load. You can then choose what to do with it. You could display it or not...

    I hope this is what you were looking for.
     
    NoamBarz, Jun 25, 2007 IP