简体   繁体   中英

problems when using a variable query and display the results in a div with ajax

i need your help! and assign the value of the variable that Comes form the php file for comparison with my query? 2. Not the correct syntax. 3. As print data to shed my office in the same div of "success"?

------ my index.html -------

<div id="formulario">
    <form method="post" id="formdata">
        <label for="nombre">Nombre: </label><input type="text" name="curp" id="curp" required="required"></br>

        <input type="button" id="botonenviar" value="Enviar">
    </form>
</div>
<div id="success" style="display:none">Sus datos han sido recibidos con éxito.</div>
<div id="fail" style="display:none">Se ha producido un error durante el envío de datos.</div>

------- My php ------

my connexion is good but..

$var= $_POST[‘curp’];    <------ is not correct!!!! 

$query = mssql_query("SELECT * FROM SOLICITUD_ACTIVOS_2010 WHERE ID_SOLICITUD = $var");


if (mssql_num_rows($query) == 0) { 
    echo json_encode(0);
} else {
    echo json_encode(1);
}

------- my script.js ---------------

$(document).ready( function() {  
$("#botonenviar").click( function() {     
    if(validaForm()){                              
        $.post("enviar.php",$("#formdata").serialize(),function(res){
            $("#formulario").fadeOut("slow");   
            if(res == 1){
                $("#success").delay(500).fadeIn("slow");
            } else {
                $("#fail").delay(500).fadeIn("slow");   
            }
        });
    }
});    

});

$var= $_POST[‘curp’]; // should be single quotes('curp') or double quotes("curp")

Your syntax here is incorrect because of the quotes, I don't know how you got that type of quote there, but that's not it. Single quote ( ' ) or double quotes( " ).

And you want to add the data returned to your #success div? Then use

$('#success').append(res); or $(res).appendTo('#success');

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM