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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -