Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Javascript - Ajax - Insertar en BD

Estas en el tema de Javascript - Ajax - Insertar en BD en el foro de Frameworks JS en Foros del Web. Que tal? A ver si pueden ayudarme... Tengo un dato obtenido de un combobox utilizando JAVASCRIPT. Este dato, lo tengo que introducir en una BD. ...
  #1 (permalink)  
Antiguo 20/05/2010, 12:11
 
Fecha de Ingreso: junio-2008
Mensajes: 137
Antigüedad: 15 años, 10 meses
Puntos: 0
Javascript - Ajax - Insertar en BD

Que tal?

A ver si pueden ayudarme...

Tengo un dato obtenido de un combobox utilizando JAVASCRIPT. Este dato, lo tengo que introducir en una BD.

Por ahora e investigando un poco... obtuve esto:

Código:
<script type="text/javascript">
function getDataServer(url, vars){
     var xml = null;
     try{
         xml = new ActiveXObject("Microsoft.XMLHTTP");
     }catch(expeption){
         xml = new XMLHttpRequest();
     }
     xml.open("GET",url + vars, false);
     xml.send(null);
     if(xml.status == 404) alert("Url no valida");
     return xml.responseText;
}
</script>

<script type="text/javascript">
function inserta(id){
    var error = getDataServer(id);
    if(error){
        alert(error);
    }
    else{

    }
}
</script>
Pero el tema es que mi script JAVASCRIPT es el siguiente:

Código:
function capturarNumero(){
        var numero = document.getElementById("numero").value;
        var maxUser = <?php echo $maxUser; ?>;
        
        if ( typeof( window[ 'arrayLocations' ] ) == "undefined" ) {
                arrayLocations = new Array();
                }

        if (arrayLocations.length < maxUser - 1) {
               arrayLocations.push(ciudad);
                }
}
Necesito introducir el valor "numero" que es el contenido del combobox en la BD y me gustaria hacerlo en este script, directamente meter el dato desde aca.

¿Como lo hago? no tengo la menor idea!

Edito: En realidad, lo mejor seria enviar mas que solo eso de informacion. Que pasa si quiero introducir en la BD mas de un dato?

Última edición por sadzas; 20/05/2010 a las 12:27 Razón: Agregar informacion
  #2 (permalink)  
Antiguo 20/05/2010, 14:01
 
Fecha de Ingreso: junio-2008
Mensajes: 137
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: Javascript - Ajax - Insertar en BD

Esto es lo que tengo hasta ahora:

Código:
function capturarNumero(){
        var numero = document.getElementById("numero").value;
        
        getDataServer(test.php, numero);
}

function getDataServer(url, vars)
{
        var xml = null;
        try {
                xml = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(expeption) {
                                        xml = new XMLHttpRequest();
                                        }
                xml.open("GET",test.php, true);
                xml.send(null);
                if(xml.status == 404) alert("Url no valida");
                        return xml.responseText;
}
pero no me funciona...

la idea es que la variable numero llegue a la pagina test.php para poder introducir el dato en la BD.
  #3 (permalink)  
Antiguo 20/05/2010, 14:39
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Javascript - Ajax - Insertar en BD

Hola

Este es el foro de javascript, no el de AJAX

Tal y como lo estás haciendo, no puede pasarle ningún valor a getDataServer. Prueba así

Cita:
function getDataServer()
{

var numero = document.getElementById("numero").value;
.....
xml.open("GET","test.php?num="+numero, true);
Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #4 (permalink)  
Antiguo 20/05/2010, 22:37
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años
Puntos: 1284
Tema movido desde javascript
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #5 (permalink)  
Antiguo 21/05/2010, 06:58
 
Fecha de Ingreso: junio-2008
Mensajes: 137
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: Javascript - Ajax - Insertar en BD

Sigo sin poder lograrlo... lo que no esta pasando son las variables, ya que el script PHP funciona barbaro (ingresa el registro, pero sin el valor enviado)

Funcion Javascript!
Código:
function capturarNumero(){
        var numero = document.getElementById("numero").value;
        var ciudad = document.getElementById("ciudad").value;
        getDataServer(numero, ciudad);
}
Funcion Ajax!
Código:
function getDataServer(url, vars)
{
        var xml = null;
        try {
                xml = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(expeption) {
                                        xml = new XMLHttpRequest();
                                        }
                xml.open("GET","test.php?num="+numero, ciudad, true);
                xml.send(null);
                if(xml.status == 404) alert("Url no valida");
                        return xml.responseText;
}
Esto no me esta enviando las variables... o por lo menos mi php no las esta capturando..

Mi pagina PHP:
Código:
<?php

//ini_set('display_errors', TRUE);
include ("./lib/defines.php");
include ("./lib/functions.php");
include ("./lib/database.php");

session_start();

$clientId = $_SESSION['clientid'];

$ciudad = $_POST['ciudad'];
$numero = $_POST['numero'];

mysql_query("insert into temporal values ('','$numero', '$ciudad')");

?>
Que estoy haciendo mal?

Etiquetas: ajax, bd, javascript
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 02:52.