elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  No recibo la variable num_usuario de archivo js a archivo php
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: No recibo la variable num_usuario de archivo js a archivo php  (Leído 1,895 veces)
madri09

Desconectado Desconectado

Mensajes: 4


Ver Perfil
No recibo la variable num_usuario de archivo js a archivo php
« en: 4 Octubre 2012, 10:01 am »

Buenos dias, necesito saber como puedo pasar una variable de un archivo js a un php.
La variable es num_usuario, y la tengo en un formulario llamado index.php en el cual puedo buscar por nº de teléfono, localidad etc. El caso es que en este index.php tengo dos solapas, una llamada Usuarios y otra Aparatos.En la primera solapa Usuarios me salen en un div un listado de los usuarios buscados, y luego con un input radio html_user += '<td ><input name="demo" type="radio" value=""/></td>';, selecciono el usuario que yo quiera y paso la variable num_usuario a la pestaña Aparatos para que me liste en otro div llamado pestaña1 los aparatos que tiene el usuario que anteriormente habia seleccionado con el input radio.El problema está en que cuando selecciono el input y pincho en la pestaña Aparatos, solo me sale el php llamado listado_aparatos.php sin nigún dato.
Agradecería algún comentario.

index.php


Código
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <script type="text/javascript" src="assets/js/jquery-1.7.2.min.js"></script>
  5. <script type="text/javascript" src="assets/jqueryui/js/jquery-ui-1.8.16.custom.min.js"></script>
  6. <script type="text/javascript" src="assets/js/js.js"></script>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  8. <title>Documento sin título</title>
  9. <link href="estilo1.css" rel="stylesheet" type="text/css" />
  10. <script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
  11. <link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
  12. <script>
  13. function mostrar(){
  14. $('#cover').html('<img src="cargando.gif">');
  15. var define ="nada"
  16. var pos_url = 'datos.php';
  17. var req = new XMLHttpRequest();
  18. if (req) {
  19. req.onreadystatechange = function() {
  20. if (req.readyState == 4 && (req.status == 200 || req.status == 304)) {
  21.  
  22. document.getElementById('cover').innerHTML = req.responseText;}}
  23.  
  24. req.open('GET', pos_url +'?define='+define,true);
  25. req.send(null);}}
  26. </script>
  27. </head>
  28. <body >
  29. <div id="contenedor">
  30. <div id="cabecera">Consulta de intervenciones</div>
  31. <div id="tabla">
  32.    <div id="formulario">
  33.    <form id="frm_filtro" method="post" action="" name="form1">
  34.            <table width="685">
  35.  <tr>
  36.    <td width="9%" class="campo_apellidos2">Teléfonos</td>
  37.    <td width="9%"><input name="telefono" type="text" size="9" /></td>
  38.    <td width="9%"><input name="telefono2" type="text" id="telefono2" size="9" /></td>
  39.    <td width="9%"><input name="telefono3" type="text" id="telefono3" size="9" /></td>
  40.    <td width="32%">&nbsp;</td>
  41.    <td width="18%" class="campo_apellidos2">NIF</td>
  42.    <td width="14%"><input name="NIF" type="text" id="NIF" size="9" /></td>
  43.  </tr>
  44.  <tr>
  45.    <td class="campo_apellidos2">Nombre</td>
  46.    <td colspan="4"><input name="nombre_apellidos" type="text" size="30" />
  47.    <td>&nbsp;</td>
  48.    <td>&nbsp;</td>
  49.  </tr>
  50.  <tr>
  51.    <td class="campo_apellidos2">Localidad</td>
  52.    <td colspan="4"><input name="poblacion" type="text" size="30" />
  53.      <span class="campo_apellidos2">C.Postal</span>      <input name="cod_postal" type="text" id="cod_postal" size="5" /></td>
  54.    <td class="campo_apellidos2">Provincia</td>
  55.    <td><input name="provincia" type="text" size="9" /></td>
  56.  </tr>
  57.  <tr>
  58.    <td class="campo_apellidos2">Calle</td>
  59.    <td colspan="4"><input name="calle" type="text" id="calle" size="45" />
  60.      <span class="campo_apellidos2"></span>      <input name="numero" type="text" id="numero" size="5" /></td>
  61.    <td class="campo_apellidos2">Edificio</td>
  62.    <td><input name="edificio" type="text" id="edificio" size="5" /></td>
  63.  </tr>
  64.  <tr>
  65.    <td class="campo_apellidos2">Puerta</td>
  66.    <td colspan="3"><input name="puerta" type="text" id="puerta" size="5" />
  67.      <span class="campo_apellidos2">      Piso</span>
  68.      <input name="piso" type="text" id="piso" size="5" />
  69.      <span class="campo_apellidos2">Letra</span>        <input name="letra" type="text" id="letra" size="5" /></td>
  70.    <td>&nbsp;</td>
  71.    <td><span class="campo_apellidos2">Nº Mante.</span></td>
  72.    <td><input name="mantenimiento" type="text" id="mantenimiento" size="5" /></td>
  73.  </tr>
  74.  </table>
  75.  <table width="100%">
  76.  <tr>
  77.    <th scope="col"><button type="button"  id="btnfiltrar" name="btnfiltrar" style="border:0; margin:0; padding:0;cursor:pointer">
  78.  <img src="imagenes_menu/boton_buscar.png"/>
  79. </button>
  80. </th>
  81.  </tr>
  82. </table>                
  83.          </form>        
  84.  
  85.    </div>
  86.    <div id="paneles">
  87.      <div id="TabbedPanels1" class="TabbedPanels">
  88.        <ul class="TabbedPanelsTabGroup">
  89.          <li class="TabbedPanelsTab" tabindex="0">Usuarios</li>
  90.          <li class="TabbedPanelsTab" tabindex="0" onclick="buscarAparatos();">Aparatos</li>
  91.          <li class="TabbedPanelsTab" tabindex="0">Intervenciones</li>
  92. </ul>
  93.        <div class="TabbedPanelsContentGroup">
  94.          <div class="TabbedPanelsContent">
  95.           <div id="usuario">
  96.            <table width="100%" id="data" class="table-dg-grid" >
  97.             <thead>
  98.              <tr>
  99.       <tr bgcolor=#DFEBFF id=t70 ondblclick='coloreaf(70,1)' onMouseOver='coloreamosin(70,1)' onMouseOut='coloreamosout(70,1)'>
  100.                    <th><span title="nu_usuario">Nº Usuario</span></th>
  101.                    <th><span title="telefono">Teléfono</span></th>
  102.                    <th><span title="nombre">Nombre</span></th>
  103.                    <th><span title="poblacion">Población</span></th>  
  104.                     </tr>
  105.                </thead>
  106.                <tbody>
  107.                </tbody>
  108.            </table>
  109.                </div>
  110.          </div>
  111.          <div class="TabbedPanelsContent" id="pestaña1" >
  112.  
  113.          </div>
  114.          <div class="TabbedPanelsContent">
  115.  
  116.          <table cellpadding="0" cellspacing="0" id="data2">
  117.                <thead>
  118.                  <tr>
  119.                    <th><span title="num_aviso"></span></th>
  120.                    <th><span title="num_usuario"></span></th>
  121.                    <th><span title="aparato"></span></th>
  122.                    <th><span title="calle"></span></th>
  123.                    <th><span title="fecha_recepcion"></span></th>
  124.                    <th><span title="fecha_recepcion"></span></th>
  125.                    <th><span title="sintoma"></span></th>
  126.                  </tr>
  127.                </thead>
  128.                <tbody>
  129.                </tbody>
  130.              </table>            
  131.          </div>
  132. </div>
  133.      </div>
  134.      <table width="100%">
  135.        <tr>
  136. <th scope="col"><a class="" href="javascript:enviar_formulario()"><span></span><img src="imagenes_menu/generar_aviso1.png" width="150" height="40" border="0"/></a>
  137. </th>
  138.          <th scope="col">&nbsp;</th>
  139.          <th scope="col"></th>
  140.          <th scope="col"><a class="" href="javascript:enviar_formulario1()"><span></span><img src="imagenes_menu/boton_salir.png" width="150" height="40" border="0"/></a>
  141. </th>
  142.        </tr>
  143.      </table>
  144.    </div>
  145. </div>
  146. </div>
  147. <script type="text/javascript">
  148. var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
  149. </script>
  150. </body>
  151. </html>
  152.  
  153.  

js.js
Código
  1. // javascript Document
  2. var ordenar = '';
  3. $(document).ready(function(){
  4.  
  5. // Llamando a la funcion de busqueda al
  6. // cargar la pagina
  7. filtrar()
  8.  
  9. var dates = $( "#del, #al" ).datepicker({
  10. yearRange: "-50",
  11. defaultDate: "+1w",
  12. changeMonth: true,
  13. changeYear: true,
  14. onSelect: function( selectedDate ) {
  15. var option = this.id == "del" ? "minDate" : "maxDate",
  16. instance = $( this ).data( "datepicker" ),
  17. date = $.datepicker.parseDate(
  18. instance.settings.dateFormat ||
  19. $.datepicker._defaults.dateFormat,
  20. selectedDate, instance.settings );
  21. dates.not( this ).datepicker( "option", option, date );
  22. }
  23. });
  24.  
  25. // filtrar al darle click al boton
  26. $("#btnfiltrar").click(function(){ filtrar() });
  27.  
  28. // boton cancelar
  29. $("#btncancel").click(function(){
  30. $(".filtro input").val('')
  31. $(".filtro select").find("option[value='0']").attr("selected",true)
  32. filtrar()
  33. });
  34.  
  35. // ordenar por
  36. $("#data th span").click(function(){
  37. var orden = '';
  38. if($(this).hasClass("desc"))
  39. {
  40. $("#data th span").removeClass("desc").removeClass("asc")
  41. $(this).addClass("asc");
  42. ordenar = "&orderby="+$(this).attr("title")+" asc"
  43. }else
  44. {
  45. $("#data th span").removeClass("desc").removeClass("asc")
  46. $(this).addClass("desc");
  47. ordenar = "&orderby="+$(this).attr("title")+" desc"
  48. }
  49. filtrar()
  50. });
  51. });
  52.  
  53. var fila= null;
  54. function pulsar(obj, num_usuario) {
  55.  obj.style.background = 'orange';
  56.  if (fila != null && fila != obj)
  57.    fila.style.background = 'white';
  58.  fila = obj;
  59. window.location ="menu1.php?id="+num_usuario;
  60. }
  61. function filtrar()
  62. {
  63. $.ajax({
  64. data: $("#frm_filtro").serialize()+ordenar,
  65. type: "POST",
  66. dataType: "json",
  67. url: "ajax.php?action=listar",
  68. success: function(data){
  69.    var html_user ='' ;
  70.    if(data.length > 0){
  71.        $.each(data, function(i,item){
  72.  
  73.  
  74.  
  75. html_user += '<tr ondblclick="pulsar(this, ' +  String.fromCharCode(39) + item.num_usuario + String.fromCharCode(39)  + ');" >';
  76. html_user += '<td ><input name="demo" type="radio" value=""/></td>';
  77. html_user += '<td >'+item.num_usuario+'</td>';
  78. html_user += '<td>'+item.telefono+'</td>';
  79. html_user += '<td>'+item.nombre+' '+item.apellidos+'</td>';
  80. html_user += '<td>'+item.poblacion+'</td>';
  81. html_user += '</tr>';
  82.  
  83.  
  84.        });                    
  85.    }
  86.    if(html_user == '') html_user = '<tr><td colspan="4" align="center">No se encontraron registros..</td></tr>';
  87.    $("#data tbody").html(html_user);
  88. }
  89.  
  90.  
  91.  });
  92. }
  93.  
  94. function createAjax(){
  95.   if (window.XMLHttpRequest)
  96.   {
  97.      xmlhttp=new XMLHttpRequest();
  98.   }
  99.   else
  100.   {
  101.      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  102.   }
  103. }
  104.  
  105. function buscarAparatos()
  106. {
  107.    var num_usuario = 0;
  108.    var elements = document.getElementsByName('demo');
  109.  
  110.    for(var x=0;elements[x];x++){
  111.        if(elements[x].checked){
  112.            num_usuario = elements[x].value;
  113.            break;
  114.        }
  115.    }
  116.  
  117.    createAjax();
  118.    xmlhttp.onreadystatechange=function()
  119.    {
  120.        if (xmlhttp.readyState==4 && xmlhttp.status==200)
  121.        {
  122.            document.getElementById("pestaña1").innerHTML=xmlhttp.responseText;
  123.        }
  124.    }
  125.   xmlhttp.open("GET","listado_aparatos.php?ID=" + num_usuario,true);
  126.   xmlhttp.send(null);
  127. }
  128.  
  129.  
  130.  


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Cambiar nombre de un archivo mediante una variable. Ayuda! -> [Ms-dos en C++]
Programación C/C++
elcyberchavo 9 20,550 Último mensaje 13 Abril 2016, 08:50 am
por Fera Core
[batch]Almacenar el contenido de un archivo .txt en una variable. « 1 2 »
Scripting
MK-Ultra 17 19,076 Último mensaje 8 Julio 2008, 17:48 pm
por Coegho
loadpicture de variable con contenido del archivo ¿como? « 1 2 3 »
Programación Visual Basic
SERBice 21 5,911 Último mensaje 25 Mayo 2008, 23:10 pm
por SERBice
Editar la variable de un archivo desde otro « 1 2 »
PHP
Servia 11 6,061 Último mensaje 12 Marzo 2009, 04:15 am
por [u]nsigned
Leer archivo con nombre variable
Scripting
Jonha000 3 3,327 Último mensaje 10 Agosto 2010, 15:42 pm
por EddyW
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines