Results 1 to 2 of 2

Thread: Ajax page include

  1. #1
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default Ajax page include

    Hello everyone,

    I currently have this script -

    HTML Code:
    <?php
        if (!isset($_GET['f'])) {
        header('Location: index.php?f=1');
        }
    ?> 
    <html>
    <head>
    <?php
    
        $page = $_GET['f'];
    	$filename = "pages/$page.php";
    	if (file_exists($filename)) {
    	$fpage = "$filename"; 
    	} else {
        $fpage = "index.php?f=2"; 
    	}
    
    ?>
    <script language="javascript">
    function HttpRequest(url){
    var pageRequest = false //variable to hold ajax object
    /*@cc_on
       @if (@_jscript_version >= 5)
          try {
          pageRequest = new ActiveXObject("Msxml2.XMLHTTP")
          }
          catch (e){
             try {
             pageRequest = new ActiveXObject("Microsoft.XMLHTTP")
             }
             catch (e2){
             pageRequest = false
             }
          }
       @end
    @*/
    
    if (!pageRequest && typeof XMLHttpRequest != 'undefined')
       pageRequest = new XMLHttpRequest()
    
    if (pageRequest){ //if pageRequest is not false
       pageRequest.open('GET', url, false) //get page synchronously 
       pageRequest.send(null)
       embedpage(pageRequest)
       }
    }
    
    function embedpage(request){
    //if viewing page offline or the document was successfully retrieved online (status code=2000)
    if (window.location.href.indexOf("http")==-1 || request.status==200)
       document.write(request.responseText)
    }
    function includepage() {
    fldrpage = "<?php echo $fpage; ?>";
    HttpRequest(fldrpage) //include page
    }
    </script>
    
    </head>
    <body onload="includepage();">
    <p>LOOK AT ME</p>
    </body>
    </html>
    and it works fine.

    I was wondering, is there any way to modify it so that it doesn't just write the contents of the included file, but the contents of this file to.

    For instance, <p>LOOK AT ME</p>
    isn't printed to the page, only the included page is.

    Any help?
    Last edited by keyboard; 02-08-2012 at 10:17 AM.

  2. #2
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    OOPS, Sorry everyone, I fixed the problem.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •