¿JavaScript/Ajax llamar php incluye es esto posible?

  • mcavady
  • Newbie
  • Newbie
  • No Avatar
  • Registrado: Jun 04, 2009
  • Mensajes: 11
  • Loc: uk
  • Status: Offline

Nota Septiembre 12th, 2011, 2:24 am

OK para después algunos trasteo que he golpeado la "pared de talento", básicamente quiero tener una llamada desde un sistema de menús de js/Jquery a la clase que llama a la otra clase para obtener los datos de la base de datos y, a continuación, destino <div> en la página y actualizar ese div.


Cada página se denomina y crea una instancia con el código siguiente;

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


así que el evento de onclick del elemento de menú llama a esto;

Código: [ 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. }


¿Hay alguna manera de que puedo hacerlo sin tener que pasar los datos en una matriz, por lo que sólo puedo usar el evento onclick para utilizar ejecutar php incluye y actualizar el div de destino?

así que básicamente esto;
Código: [ 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. }


o esto podría ayudar a mostrar lo que quiero hacer;

Código: [ 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. }


Si tiene sentido???
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Septiembre 12th, 2011, 2:24 am

  • mcavady
  • Newbie
  • Newbie
  • No Avatar
  • Registrado: Jun 04, 2009
  • Mensajes: 11
  • Loc: uk
  • Status: Offline

Nota Septiembre 12th, 2011, 4:32 am

Después de algunos cachondeo sobre ello parecería que puede utilizar el evento onlick para usar Ajax/Jquery pero no puede tener llamada Ajax/Jquery incluye page.php.

Lectura más para mí pensar
  • mcavady
  • Newbie
  • Newbie
  • No Avatar
  • Registrado: Jun 04, 2009
  • Mensajes: 11
  • Loc: uk
  • Status: Offline

Nota Septiembre 12th, 2011, 5:51 am

OK después algunos cachondeo más acerca de esto no funciona bien!

Archivo = menu.js
Código: [ 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. });


Archivo = getHomePage.php

Código: [ 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. ?>


Ahora recibo este código de error

    Acceso denegado para el usuario "www-data"@"localhost" (using password: NO)

Esto es un poco mejor, pero ahora necesito ordenar el archivo perms para conseguir que funcione desee.

Creo

dice que se carga pero no mostrarlo.

:(
  • mcavady
  • Newbie
  • Newbie
  • No Avatar
  • Registrado: Jun 04, 2009
  • Mensajes: 11
  • Loc: uk
  • Status: Offline

Nota Septiembre 12th, 2011, 7:16 am

OK por lo que después de leer un poco, me siento un poco tonto para no llamar a conectar y desconectar antes y después de la llamada que quería hacer. Como una solución alternativa ha agregado una "capa" de obtener archivos de php para los diferentes elementos de menú. pero básicamente aquí es el trabajo que he logrado.

Menu.html
Código: [ 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
Código: [ 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

Código: [ 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. ?>


Obras irme:P

Espero que esto ayude a si alguno tiene cualquier consejos sobre cómo hacer esto de una manera mejor entonces por favor comentar:)

Publicar Información

  • Total de mensajes en este tema: 4 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 156 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC