JavaScript/Ajax to call php includes is this possible ?

  • mcavady
  • Newbie
  • Newbie
  • mcavady
  • Posts: 11
  • Loc: uk

Post 3+ Months Ago

Ok so after some fiddling around I have hit the "talent wall", Basically I want to have an call from a js/Jquery menu system to the class that calls the other class to get the data from the db and then target a <div> on the page and refresh that div.


Each page is called and an instance created with the following code;

Code: [ Select ]
include_once "content_home.class.php";
$Home = new home();
  1. include_once "content_home.class.php";
  2. $Home = new home();


so the menu item onclick event calls this;

Code: [ Select ]
function showHomePage()
{
document.getElementById('content').innerHTML="homePageContent.php"; //this is were I want the targeting to be done
}
  1. function showHomePage()
  2. {
  3. document.getElementById('content').innerHTML="homePageContent.php"; //this is were I want the targeting to be done
  4. }


Is there a way that I can do this without having to pass the data into an array, so I can just use the onclick event to use run php includes and update the target div?

so basically this ;
Code: [ Select ]
function showHomePage()
{
document.getElementById('content').innerHTML= "<?php include_once "content_home.class.php"; $Home = new home();?>"
}
  1. function showHomePage()
  2. {
  3. document.getElementById('content').innerHTML= "<?php include_once "content_home.class.php"; $Home = new home();?>"
  4. }


or this might help show what I want to do;

Code: [ Select ]
function showHomePage()
{
document.getElementById('content').innerHTML= '<?php require_once "content_home.class.php";?>'
+'<?php $Home = new home()?>';
}
  1. function showHomePage()
  2. {
  3. document.getElementById('content').innerHTML= '<?php require_once "content_home.class.php";?>'
  4. +'<?php $Home = new home()?>';
  5. }


If that makes sense ??
  • mcavady
  • Newbie
  • Newbie
  • mcavady
  • Posts: 11
  • Loc: uk

Post 3+ Months Ago

After some further messing about it would seem that I can use the onlick event to use Ajax/Jquery but cannot have Ajax/Jquery call includes page.php.

More reading for me I think
  • mcavady
  • Newbie
  • Newbie
  • mcavady
  • Posts: 11
  • Loc: uk

Post 3+ Months Ago

ok after some more messing about this does not work either !

File = menu.js
Code: [ Select ]
function showHomePage()
{
$.get('getHomePage.php', function(data) {
 $('.result').html(data);
    document.getElementById('zpp_content').innerHTML = data;
 alert('Load was performed.');
});
  1. function showHomePage()
  2. {
  3. $.get('getHomePage.php', function(data) {
  4.  $('.result').html(data);
  5.     document.getElementById('zpp_content').innerHTML = data;
  6.  alert('Load was performed.');
  7. });


File = getHomePage.php

Code: [ Select ]
<?php
require_once "zpp_content_home.class.php";
  $Home = new home();
?>
  1. <?php
  2. require_once "zpp_content_home.class.php";
  3.   $Home = new home();
  4. ?>


I now get this error code

    Access denied for user 'www-data'@'localhost' (using password: NO)

This is a little better but now I need to sort out the file perms to get it to work they way I want.

I think

it says that it is loaded but does not display it.

:(
  • mcavady
  • Newbie
  • Newbie
  • mcavady
  • Posts: 11
  • Loc: uk

Post 3+ Months Ago

Ok so after some reading I feel a bit of a fool for not calling the connect and disconnect before and after the call I wanted to make. As a work around I have added a "layer" of get php files for the different menu items. but basically here is the work around that I have managed.

menu.html
Code: [ Select ]
<div id="mainMenuContainer" >
<div id="pane_one" onclick="showHomePage()">
</div>
  1. <div id="mainMenuContainer" >
  2. <div id="pane_one" onclick="showHomePage()">
  3. </div>


menu.js
Code: [ Select ]
function showHomePage() // function name
{
$.get('getHomePage.php', function(data) { //get the data from the file
 $('.result').html(data); //get the result ready for use
    document.getElementById('content').innerHTML = data; //target the div with the data
 alert('Load was performed.'); //for testing to say the file had loaded
});
}
  1. function showHomePage() // function name
  2. {
  3. $.get('getHomePage.php', function(data) { //get the data from the file
  4.  $('.result').html(data); //get the result ready for use
  5.     document.getElementById('content').innerHTML = data; //target the div with the data
  6.  alert('Load was performed.'); //for testing to say the file had loaded
  7. });
  8. }


getPage.php

Code: [ Select ]
<?php
include_once "config.class.php";//this holds the connect and disconnect functions
  $Connect = new connect();//initiate the class (connect)

include_once "content_about.class.php"; //get page and creat instance
  $Post = new post(); //place data ready for use

include_once "config.class.php";//this holds the connect and disconnect functions
  $Connect = new disconnect();//initiate the class (disconnect)

?>
  1. <?php
  2. include_once "config.class.php";//this holds the connect and disconnect functions
  3.   $Connect = new connect();//initiate the class (connect)
  4. include_once "content_about.class.php"; //get page and creat instance
  5.   $Post = new post(); //place data ready for use
  6. include_once "config.class.php";//this holds the connect and disconnect functions
  7.   $Connect = new disconnect();//initiate the class (disconnect)
  8. ?>


It Works GO Me :P

I hope this helps if any one has any tips on how to do this in a better way then please comment :)

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 20 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.