Foros del Web » Programando para Internet » Jquery »

Ajax funciona en un servidor pero en otro no

Estas en el tema de Ajax funciona en un servidor pero en otro no en el foro de Jquery en Foros del Web. Que tal amigos del foro, les agradezco mucho la ayuda y el tiempo que siempre proporcionan. Les cuento que tengo un problema: tengo un código ...
  #1 (permalink)  
Antiguo 10/06/2014, 14:44
 
Fecha de Ingreso: marzo-2012
Mensajes: 84
Antigüedad: 12 años, 1 mes
Puntos: 3
Ajax funciona en un servidor pero en otro no

Que tal amigos del foro, les agradezco mucho la ayuda y el tiempo que siempre proporcionan. Les cuento que tengo un problema:
tengo un código donde hago una llamada a una consulta por medio de ajax, lo he probado en un servidor y funciona perfectamente, sin embargo cuando lo subo a otro servidor no funciona, ¿a qué se deberá?

Gracias por su ayuda

Código HTML:
Ver original
  1. <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
  2. <script type="text/javascript" src="js/llamada_ajax.js"></script>
  3. </head>
  4. <div id="content">
  5.         <div class="filtro">
  6.             <form id="frm_filtro" method="post" action="">
  7.                 <ul>
  8.                 <table width="100%" border="0">
  9.   <tr>
  10.     <td width="40%"><li><label>Fecha: &nbsp;&nbsp; del</label>
  11.                         <input name="datepickerDel" id="datepickerDel" type="text" size="14">
  12.                         al
  13.                         <input name="datepickerAl" id="datepickerAl" type="text" size="14"></li></td>
  14.     <td width="40%"><li><label>Tipo de usuario:</label>
  15.                         <select name="tipo_usuario" id="tipo_usuario" style="width:185px">
  16.                             <option value="0">Elige</option>
  17.                             <?php
  18.                            $query = mysql_query("SELECT * FROM cat_tipo_usuario ORDER BY tipo_usuario");
  19.                            while($row = mysql_fetch_array($query)){
  20.                                ?>
  21.                                 <option value="<?php echo $row['id_tipo_usuario'] ?>">
  22.                                     <?php echo $row['tipo_usuario'] ?>
  23.                                 </option>
  24.                                 <?php
  25.                            }
  26.                            ?>
  27.                         </select>              
  28.                     </li></td>
  29.     <td width="20%"><li>
  30.                         <button type="button" id="btnfiltrar">Filtrar</button>
  31.                     </li>    
  32.                    
  33.                     <li>
  34.                         <a href="javascript:;" id="btncancel">Todos</a>
  35.                     </li></td>
  36.   </tr>
  37.   <tr>
  38.     <td width="40%"><li><label>Palabras:</label> <input type="text" name="palabras" id="palabras" size="40" /></li></td>
  39.     <td width="40%"><li><label>Tipo de visita:</label>
  40.                         <select name="tipo_visita" id="tipo_visita" style="width:200px">
  41.                             <option value="0">Elige</option>
  42.                             <?php
  43.                            $query = mysql_query(" SELECT * FROM dat_documentos GROUP BY nombre ");
  44.                            while($row = mysql_fetch_array($query)){
  45.                                ?>
  46.                                 <option value="<?php echo $row['id_documento'] ?>">
  47.                                     <?php echo $row['nombre'] ?>
  48.                                 </option>
  49.                                 <?php
  50.                            }
  51.                            ?>
  52.                         </select>                  
  53.                     </li></td>
  54.     <td width="20%">&nbsp;</td>
  55.   </tr>
  56.                 </ul>
  57.             </form>
  58.         </div>
  59.        
  60.         <br>
  61.     <div id="lineaPunteada"></div>
  62.     <br>
  63.        
  64.         <table cellpadding="0" cellspacing="0" id="data" width="100%">
  65.             <thead>
  66.                 <tr>
  67.                     <th width="20%" align="center"><span title="usuario">Usuario</span></th>
  68.                     <th width="10%" align="center"><span title="tipo_usuario">Tipo de usuario</span></th>
  69.                     <th width="30%" align="center"><span title="documento">Tipo de visita</span></th>
  70.                     <th width="10%" align="center"><span title="archivo">Documento</span></th>
  71.                     <th width="10" align="center"><span title="instructivo">Instructivo</span></th>
  72.                     <th width="20%" align="center"><span title="fecha">Fecha</span></th>
  73.                 </tr>
  74.             </thead>
  75.             <tbody>
  76.                
  77.             </tbody>
  78.         </table>
  79.     </div>
  80. </body>

llamada_ajax.js
Código Javascript:
Ver original
  1. / JavaScript Document
  2. var ordenar = '';
  3. $(document).ready(function(){
  4.    
  5.     // filtrar al darle click al boton
  6.     $("#btnfiltrar").click(function(){ filtrar() });
  7.    
  8.     // boton cancelar
  9.     $("#btncancel").click(function(){
  10.         $(".filtro input").val('')
  11.         $(".filtro select").find("option[value='0']").attr("selected",true)
  12.         filtrar()
  13.     });
  14.    
  15.     // ordenar por
  16.     $("#data th span").click(function(){
  17.         var orden = '';
  18.         if($(this).hasClass("desc"))
  19.         {
  20.             $("#data th span").removeClass("desc").removeClass("asc")
  21.             $(this).addClass("asc");
  22.             ordenar = "&orderby="+$(this).attr("title")+" asc"     
  23.         }else
  24.         {
  25.             $("#data th span").removeClass("desc").removeClass("asc")
  26.             $(this).addClass("desc");
  27.             ordenar = "&orderby="+$(this).attr("title")+" desc"
  28.         }
  29.         filtrar()
  30.     });
  31. });
  32.  
  33. function filtrar()
  34. {  
  35.     $.ajax({
  36.         data: $("#frm_filtro").serialize()+ordenar,
  37.         type: "POST",
  38.         dataType: "json",
  39.         url: "filtro_reportes/ajax.php?action=listar",
  40.             success: function(data){
  41.                 var html = '';
  42.                 if(data.length > 0){
  43.                     $.each(data, function(i,item){
  44.                         html += '<tr>'
  45.                             html += '<td width="20%" align="center">'+item.usuario+'</td>'
  46.                             html += '<td width="10%" align="center">'+item.tipo_usuario+'</td>'
  47.                             html += '<td width="30%" align="center">'+item.documento+'</td>'
  48.                             html += '<td width="10%" align="center">'+item.archivo+'</td>'
  49.                             html += '<td width="10%" align="center">'+item.instructivo+'</td>'
  50.                             html += '<td width="20%" align="center">'+item.fecha+'</td>'
  51.                         html += '</tr>';
  52.                                                            
  53.                     });                
  54.                 }
  55.                 if(html == '') html = '<tr><td colspan="6" align="center">No se encontraron registros...</td></tr>'
  56.                 $("#data tbody").html(html);
  57.             }
  58.       });
  59. }

ajax.php
Código PHP:
Ver original
  1. include ("../conexion_mysql.php");
  2.  
  3. if($_GET['action'] == 'listar')
  4. {
  5.     // valores recibidos por POST
  6.     $vnm   = $_POST['palabras'];
  7.     $vtipo_user = $_POST['tipo_usuario'];
  8.     $vtipo_visita = $_POST['tipo_visita'];
  9.     $vdel  = $_POST['datepickerDel'];
  10.     $val   = $_POST['datepickerAl'];
  11.    
  12.     $sql = " SELECT
  13.     dat_visitas.id_visitas,
  14.     cat_usuarios.nombre,
  15.     cat_tipo_usuario.tipo_usuario,
  16.     dat_visitas.fecha,
  17.     dat_documentos.nombre,
  18.     dat_visitas.archivo,
  19.     dat_visitas.instructivo
  20.     FROM dat_visitas
  21.     INNER JOIN cat_usuarios ON cat_usuarios.id_usuario = dat_visitas.id_usuario
  22.     INNER JOIN cat_tipo_usuario ON cat_tipo_usuario.id_tipo_usuario = cat_usuarios.tipo_usuario
  23.     INNER JOIN dat_documentos ON dat_documentos.id_documento = dat_visitas.documento
  24.     ";
  25.                                        
  26.     // Vericamos si hay algun filtro
  27.     $sql .= ($vnm != '')      ? " WHERE CONCAT(cat_usuarios.nombre,' ', dat_documentos.nombre,' ', cat_tipo_usuario.tipo_usuario) LIKE '%$vnm%' ORDER BY dat_visitas.fecha DESC" : "";
  28.     $sql .= ($vtipo_user > 0)      ? " WHERE cat_usuarios.tipo_usuario = '".$vtipo_user."' ORDER BY dat_visitas.fecha DESC" : "";
  29.     $sql .= ($vtipo_visita > 0)      ? " WHERE dat_documentos.id_documento = '".$vtipo_visita."' ORDER BY dat_visitas.fecha DESC" : "";
  30.     $sql .= ($vdel && $val)   ? " WHERE dat_visitas.fecha BETWEEN '$vdel'
  31.                                                         AND '$val' ORDER BY dat_visitas.fecha DESC" : "";
  32.    
  33.     // Ordenar por
  34.     $vorder = $_POST['orderby'];
  35.    
  36.     if($vorder != ''){
  37.         $sql .= " ORDER BY ".$vorder;
  38.     }
  39.    
  40.     $query = mysql_query($sql);
  41.     $datos = array();
  42.    
  43.     while($row = mysql_fetch_row($query))
  44.     {      
  45.        
  46.         $fecha=explode(" ",$row[3]);
  47.         $explode=explode("-",$fecha[0]);
  48.         $ano=$explode[0];
  49.         $mes=$explode[1];
  50.         $dia=$explode[2];
  51.    
  52.         $datos[] = array(
  53.             'usuario'               => utf8_encode($row[1]),
  54.             'tipo_usuario'          => utf8_encode($row[2]),
  55.             'documento'             => utf8_encode($row[4]),
  56.             'archivo'               => $row[5],
  57.             'instructivo'           => $row[6],
  58.             'fecha'                 => $dia."-".$mes."-".$ano
  59.         );
  60.     }
  61.     // convertimos el array de datos a formato json
  62.     echo json_encode($datos);
  63. }
  #2 (permalink)  
Antiguo 10/06/2014, 17:33
Avatar de ipraetoriux  
Fecha de Ingreso: abril-2010
Ubicación: ipraetoriux.com
Mensajes: 1.125
Antigüedad: 14 años
Puntos: 155
Respuesta: Ajax funciona en un servidor pero en otro no

...pues en el servidor que no te funciona, verifica que la ruta de la url de la función $.ajax() sea correcta, verifica que error te da usando la herramienta para desarrolladores de Chrome / Safari o Firebug en FF.
  #3 (permalink)  
Antiguo 10/06/2014, 18:01
Avatar de livemusic  
Fecha de Ingreso: abril-2011
Ubicación: Lima - Chorrillos
Mensajes: 150
Antigüedad: 13 años
Puntos: 18
Respuesta: Ajax funciona en un servidor pero en otro no

Verifica tu archivo conexion_mysql.php ... xD
  #4 (permalink)  
Antiguo 11/06/2014, 09:51
 
Fecha de Ingreso: marzo-2012
Mensajes: 84
Antigüedad: 12 años, 1 mes
Puntos: 3
Respuesta: Ajax funciona en un servidor pero en otro no

Muchas gracias ipraetoriux y livemusic por su ayuda.

En cuanto a lo que me dices livemusic acabo de verificar la conexión y se encuentra todo bien, de hecho puedo ver mis otras consultas sin problemas, sólo el único punto en donde no puedo visualizarlas es cuando uso Ajax.

Por otra parte revisé la ruta de la función $.ajax() y se encuentra correcta, también hice un análisis con el Firebug Lite de Chrome como me indicaste ipraetoriux y no aparece ningún error.

¿Qué más podría hacer para resolver mi problema?

Gracias.

Etiquetas: ajax, javascript, php
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 10:12.