Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Codigo Ajax + PHP no me funciona

Estas en el tema de Codigo Ajax + PHP no me funciona en el foro de PHP en Foros del Web. He hecho de todo, mirado requete tutoriales, ejemplos y respuestas en el foro y no he encontrado el problema a lo siguiente he hecho: Html: ...
  #1 (permalink)  
Antiguo 31/07/2015, 15:46
Avatar de Fleon  
Fecha de Ingreso: febrero-2010
Mensajes: 138
Antigüedad: 14 años, 2 meses
Puntos: 3
Codigo Ajax + PHP no me funciona

He hecho de todo, mirado requete tutoriales, ejemplos y respuestas en el foro y no he encontrado el problema a lo siguiente he hecho:

Html:

Código HTML:
Ver original
  1. <tr id="convert_ users">
  2.     <td width="10%" valign="top" class="textbox">Members</td>
  3.     <td width="10%">
  4.         <div id="icon_users" style="font-size: smaller; margin-bottom: 2ex;"><a href="#" id="link" data-table="users"><img src="./extra/script_go.png" /></a></div>
  5.     </td>
  6.     <td style="display: none;">
  7.         <div id="loading_users"><img src="./extra/ajax-loader.gif" /></div>
  8.     </td>
  9.     <td>
  10.         <div id="status_users"></div>
  11.     </td>          
  12. </tr>

JavaScript:

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. $(function(){
  3.     $(\'#link\').click(function(){
  4.         var elem = $(this);
  5.         $(\'#loading-\'+elem.attr(\'data-table\')).show();
  6.         $.ajax({
  7.             type: "GET",
  8.             url: "convert.php",
  9.             data: "action="+elem.attr(\'data-table\'),
  10.             dataType:"html",  
  11.             success: function(data) {
  12.                 if(data.success){
  13.                        elem.hide();
  14.                        $(\'#status_\'+elem.attr(\'data-table\')).html(data);
  15.                 }
  16.             }
  17.             complete: function(){
  18.             $(\'#loading-\'+elem.attr(\'data-table\')).hide();
  19.             }
  20.         });
  21.         return false;
  22.     });
  23. });
  24. </script>

PHP:

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

lo estoy haciendo desde un link debido a que la pagina ya cuenta con un formulario y no pueden haber dos o uno dentro de otro, deseo obtener el resultado en el bloque #status_users, mostrar el loader y esconder luego, pero nada me funciona. Nota: todo esta dentro de un echo en PHP.
  #2 (permalink)  
Antiguo 31/07/2015, 18:15
Avatar de Fleon  
Fecha de Ingreso: febrero-2010
Mensajes: 138
Antigüedad: 14 años, 2 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!

Etiquetas: ajax, formulario, html
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:42.