Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
innerHTML a PHP include?
Old 10-02-2008, 08:53 PM innerHTML a PHP include?
Super Talker

Posts: 132
Trades: 0
Is it possible to put an include in innerHTML?

It didn't seem to work for me.

Code:
var.onclick = function() {
    var2.innerHTML = "<?php include('file.html'); ?>";
}
Is what I tried to do.

I know I have to learn some ajax now but I have never toucehd ajax so any guidance would be graaaaaaaand.

Last edited by soap; 10-02-2008 at 08:55 PM..
soap is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-02-2008, 09:33 PM Re: innerHTML a PHP include?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Whatever is in the <?php include?> will be returned exactly where you put it. You need to simply look at your source code to see how it looks. The most important thing to consider is likely the inclusion of quotes within quotes, which need to be backslashed in any case. Your idea is unique, and perhaps not terrible, but limited by that fact.

It is possible to include bits of HTML with AJAX, with a method that has become known by some as AHAH. It isn't that hard, if you get the hang of it.

If you are like me, it is even easier. I do it with jQuery, in a single line, like this:
Code:
$("#someid").load("path/to/file.php");
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 10-03-2008, 03:46 PM Re: innerHTML a PHP include?
Super Talker

Posts: 132
Trades: 0
Right since it's dynamically loading according to a link a user clicks on it will have to speak with the server again if i want to use an include.

I already have this working with iframes but there was some freak out with the client with SEO and search engines not reading content in iframes and such.
soap is offline
Reply With Quote
View Public Profile
 
Old 10-03-2008, 04:01 PM Re: innerHTML a PHP include?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
loading content via javascript won't be seen by search engines either.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-03-2008, 08:28 PM Re: innerHTML a PHP include?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
What you should do it load the content statically, add a CSS class to it that makes it invisible, then onclick, remove the class, and presto, it appears!
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 10-04-2008, 05:14 AM Re: innerHTML a PHP include?
Junior Talker

Posts: 2
Trades: 0
Hello,

Well, that's certainly not possible.

Include is a server side directive for PHP to include a file that's listed.

PHP - is a server side language. I.e., it works before the content reaches the browser.

Javscript is a client side language. I.e. it works after the content reaches the browser.

So when in any client side script there's no way to use any PHP function like Include, cause PHP is just not there to process the instructions.

Hope that helped

Cyril gupta
cyrilgupta is offline
Reply With Quote
View Public Profile
 
Old 10-04-2008, 12:18 PM Re: innerHTML a PHP include?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I know I have to learn some ajax now but I have never toucehd ajax so any guidance would be graaaaaaaand.
A basic AJAX call to include the output from an PHP file would be
Code:
<script type="text/javascript">
function ajaxFunction()
{
var oRequest;
try {
        oRequest=new XMLHttpRequest();
     } catch (e)   {
     try {
          oRequest=new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
          try {
              oRequest=new ActiveXObject("Microsoft.XMLHTTP");
               } catch (e) {
                   alert("Your browser does not support AJAX!");
                  return false;
               }
         }
      }
   oRequest.onreadystatechange=function() {
    if(oRequest.readyState==4)
      {
          document.getElementById("var2").innerHTML = oRequest.responseText;
      }
    }
  oRequest.open("GET","file.php",true);
  oRequest.send(null);
  }
</script>
file.php would look like;
PHP Code:
<?php include('file.html'); ?>
I'll not overload you with reuseable objects at this stage.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to innerHTML a PHP include?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25133 seconds with 12 queries