Ver Mensaje Individual
  #2 (permalink)  
Antiguo 31/07/2015, 18:15
Avatar de Fleon
Fleon
 
Fecha de Ingreso: febrero-2010
Mensajes: 138
Antigüedad: 14 años, 3 meses
Puntos: 3
Respuesta: Codigo Ajax + PHP no me funciona

lo pude resolver de la siguiente manera:

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.             $(function(){
  3.                 $(\'.converter\').click(function(){
  4.                     var elem = $(this);
  5.                     var table = elem.attr(\'id\');
  6.                     var request = $.ajax({
  7.                       url: "convert.php",
  8.                       type: "POST",
  9.                       data: {action : table},
  10.                       dataType: "html"
  11.                     });
  12.                     $(\'#loading_\'+table).html(\'<img src="', $incontext['extra']['icon_loader'] ,'" />\');
  13.                     request.done(function(msg) {
  14.                         $(\'#loading_\'+table).html(\'<img src="', $incontext['extra']['icon_ok'] ,'" />\');
  15.                         $("#status_"+table).html( msg );
  16.                     });
  17.                    
  18.                     request.fail(function(jqXHR, textStatus) {
  19.                       $("#status_"+table).html( "Error: " + textStatus );
  20.                     });  
  21.                 });
  22.             });
  23.         </script>

Código PHP:
Ver original
  1. <?php
  2.  
  3.     $actions = array(
  4.         'users' => 'convertMembers',
  5.         'categories' => 'convertCats',
  6.     );
  7.  
  8.     if(isset($_POST['action']))
  9.         call_user_func($actions[$_POST['action']]);
  10.  
  11. function convertMembers()
  12. {
  13.     global $incontext, $txt;
  14.    
  15.     $text = 'Converting Members';
  16.     echo $text;
  17. }
  18.  
  19. ?>

Gracias!