[英]problems when using a variable query and display the results in a div with ajax
我需要你的幫助! 並分配來自PHP文件的變量值與我的查詢進行比較? 2.語法不正確。 3.作為打印數據在“成功”的同一div上流失我的辦公室?
------我的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>
-------我的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);
}
-------我的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")
由於引號,您在這里的語法不正確,我不知道您是怎么得到這種類型的引號的,但不是那樣。 單引號( '
)或雙引號( "
)。
您是否要將返回的數據添加到#success
div中? 然后使用
$('#success').append(res); or $(res).appendTo('#success');
希望能有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.