SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php include with javascript - Help

    Hello,

    is there a way to insert a "php include" in my html code, with javascript
    by clicking a button?

    please help

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,423
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Yes, you would need to use Ajax to get the PHP information and then insert it into the page. You have to remember that the PHP will execute on the server first and then over the results though Ajax.

  3. #3
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is an example code of what I mean:

    Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="javascript">
    <!--
    function php_include(){
    my_left = "<";
    my_right = ">";
    document.getElementById('google').innerHTML = my_left + "?php include 'http://www.msn.com'; ?" + my_right;
    
    }
    //-->
    </script>
    </head>
    
    <body>
    <input onClick="php_include()"  name="" type="button" value="test"> 
    
    <div id="google">
    <?php include 'http://www.google.com'; ?>
    </div>
    
    
    </body>
    </html>

  4. #4
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try
    Code:
    <div id="google">
    <iframe src='http://www.google.com'>
    </div>

  5. #5
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes ok I know, but in the original application, not in this example, I want to
    have access to the images of the included file with javascript.

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    Lucknow, UP, India
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what you want is this :arrow:
    HTML Code:
    <script>
    // Get Base URL
    URL = document.location.href;
    xend = URL.lastIndexOf("/") + 1;
    var Base_URL = URL.substring(0, xend);
    
    function showData()
    {
     scrObj = document.createElement('SCRIPT');
     scrObj.type = 'text/javascript';
     scrObj.src = Base_URL + 'getContents.php?type=pics&cat='+Cat+'&subcat='+SubCat;
     document.body.appendChild(scrObj);
    }
    </script>
    its a snip from my AJAX library and does not give ActiveX errors on IE.
    just change getContents.php line to suit yourself.
    Who the hell is "General Failure"
    and why is he reading my hard disk???

  7. #7
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,423
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Please don't cross-post. Not only is it against the rules but it makes it harder for people to help you.

    http://www.sitepoint.com/forums/showthread.php?t=374414


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
  •