Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/10/2012, 13:07
Avatar de satjaen
satjaen
 
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 7 meses
Puntos: 10
Pasar variable de funcion ajax

Hola estoy intentando pasar una variable de ajax a un php pero no me sale.
Por favor, puede ayudarme alguien?
Este es el js, donde tengo un input radio y paso la variable num_aviso al php.
html_user += '<td ><input name="demo" type="radio" value="demo"/></td>';
Código Javascript:
Ver original
  1. function filtrar()
  2. {  
  3.     $.ajax({
  4.         data: $("#frm_filtro").serialize()+ordenar,
  5.         type: "POST",
  6.         dataType: "json",
  7.         url: "ajax.php?action=listar",
  8.             success: function(data){
  9.     var html_user ='' ;
  10.     if(data.length > 0){
  11.         $.each(data, function(i,item){
  12.        
  13.        
  14.          
  15.  html_user += '<tr ondblclick="pulsar(this, ' +  String.fromCharCode(39) + item.num_usuario + String.fromCharCode(39)  + ');" >';
  16.  html_user += '<td ><input name="demo" type="radio" value="demo"/></td>';
  17.  html_user += '<td >'+item.num_usuario+'</td>';
  18.  html_user += '<td>'+item.telefono+'</td>';
  19.  html_user += '<td>'+item.nombre+' '+item.apellidos+'</td>';
  20.  html_user += '<td>'+item.poblacion+'</td>';
  21.  html_user += '</tr>';
  22.            
  23.                                  
  24.         });                    
  25.     }
  26.     if(html_user == '') html_user = '<tr><td colspan="4" align="center">No se encontraron registros..</td></tr>';
  27.     $("#data tbody").html(html_user);
  28. }
  29.  
  30.            
  31.       });
  32. }
  33.  
  34. function createAjax(){
  35.    if (window.XMLHttpRequest)
  36.    {
  37.       xmlhttp=new XMLHttpRequest();
  38.    }
  39.    else
  40.    {
  41.       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  42.    }
  43. }
  44.  
  45. function buscarAparatos()
  46. {
  47.     var num_usuario = 0;
  48.     var elements = document.getElementsByName('demo');
  49.    
  50.     for(var x=0;elements[x];x++){
  51.         if(elements[x].checked){
  52.             num_usuario = elements[x].value;
  53.             break;
  54.         }
  55.     }
  56.    
  57.     createAjax();
  58.     xmlhttp.onreadystatechange=function()
  59.     {
  60.         if (xmlhttp.readyState==4 && xmlhttp.status==200)
  61.         {
  62.             document.getElementById("pestaña1").innerHTML=xmlhttp.responseText;
  63.         }
  64.     }
  65.    xmlhttp.open("GET","listado_aparatos.php?ID=" + num_usuario,true);
  66.    xmlhttp.send(null);
  67. }

y recupero la variable num_usuario con:

Código PHP:
$num_usuario=$_GET['id'];
mysql_select_db($database_conexion$conexion);
$query_Recordset1 "SELECT * FROM ap_usuarios where num_usuario like '$num_usuario'";
$Recordset1 mysql_query($query_Recordset1$conexion) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);