Ver Mensaje Individual
  #2 (permalink)  
Antiguo 13/05/2013, 22:40
Avatar de rottenp4nx
rottenp4nx
 
Fecha de Ingreso: octubre-2012
Ubicación: Santiago
Mensajes: 417
Antigüedad: 11 años, 6 meses
Puntos: 36
Respuesta: Llamar funcion php desde jquery

Código HTML:
Ver original
  1. <select id="valores">
  2.    <option value="1">Opcion 1</option>
  3.    <option value="2">Opcion 2</option>
  4.    <option value="3">Opcion 3</option>
  5.  
  6. <input type="text" id="cajatexto">

Código Javascript:
Ver original
  1. $(document).ready(iniciar);
  2.  
  3. function iniciar(){
  4.     $("#valores").change(mostrarTitulo);
  5. }
  6.  
  7. function mostrarTitulo(){
  8.     var x = $(this).val();
  9.     $.ajax({
  10.         url: "mipagina.php",
  11.        type: "post",
  12.        data: "valor="+x,
  13.        success: function(data){
  14.            $("#cajatexto").val(data);
  15.        }
  16.     });
  17. }

Código PHP:
Ver original
  1. $valor = $_POST['valor'];
  2.  
  3. function obtenerTitulo($val){
  4.     //conexion
  5.    $sql = "select titulo from mitabla where id = $val";
  6.    $reg = mysql_query($sql);
  7.    $r = mysql_fetch_array($reg);
  8.    return $r['titulo'];
  9. }
  10.  
  11. echo obtenerTitulo($valor);

PD: http://www.cristalab.com/tutoriales/...-jquery-c226l/

Saludos