Ver Mensaje Individual
  #2 (permalink)  
Antiguo 27/12/2014, 00:35
moginn
(Desactivado)
 
Fecha de Ingreso: enero-2013
Mensajes: 289
Antigüedad: 11 años, 3 meses
Puntos: 10
Respuesta: Acceder a una función de una clase de PHP Ajax de Jquery

Use $.ajax to call a server context (or URL, or whatever) to invoke a particular 'action'. What you want is something like:

Código Javascript:
Ver original
  1. $.ajax({ url: '/my/site',
  2.          data: {action: 'test'},
  3.          type: 'post',
  4.          success: function(output) {
  5.                       alert(output);
  6.                   }
  7. });

On the server side, the action POST parameter should be read and the corresponding value should point to the method to invoke, e.g.:

Código PHP:
Ver original
  1. if(isset($_POST['action']) && !empty($_POST['action'])) {
  2.     $action = $_POST['action'];
  3.     switch($action) {
  4.         case 'test' : test();break;
  5.         case 'blah' : blah();break;
  6.         // ...etc...
  7.     }
  8. }