jquery - How can I retrive data from db with ajax and php? -
i'm trying check if field present db before submit form.
so add keyup event field data db
ajax
.
so have form add code:
$(document).ready(function (){ $("#matricola").keyup(function () { $.ajax({ type:"get", url: "getmatricolaajax.php", data: {'type':'user', 'matricola':$("#matricola").val()}, datatype: "text", success: function(result){ console.log("ok"); $("#matricola").val(""); alert("matricola "+ result +" già presente!!"); }, error: function(){ console.log("ko"); } }); }); });
and getmatricolaajax.php
:
<script src='js/jquery-2.1.4.js' type="text/javascript"></script> <?php require_once 'config.php'; require_once function_path.'/dbfunction.php'; if($_get['type'] == "user"){ $querymatricolamatch = 'select * user matricola = "'.$_get['matricola'].'"'; }else{ $querymatricolamatch = 'select * 150ore matricola = "'.$_get['matricola'].'"'; } echo $querymatricolamatch; $conn = dbconnect($userdb, $passworddb, $namedb); $matricola = dbquerygetresult($querymatricolamatch); dbdisconnect($conn); echo $matricola;
it works half, beacause in result
obtain html
code getmatricolaajax.php
..
why??
how can matricola
??
comment or remove datatype: "text"
, try again.
$.ajax({ type:"get", url: "getmatricolaajax.php", data: {'type':'user', 'matricola':$("#matricola").val()}, // datatype: "text", success: function(result){ console.log("ok"); $("#matricola").val(""); alert("matricola "+ result +" già presente!!"); },
or else can use json_encode() in php data json object array.
Comments
Post a Comment