简体   繁体   中英

Using Multiple Parameter Two Get DB Value From PHP Using Ajax And jQuery

I'm still new in web programming, I got trouble when get result form mysql. I'm using two parameter to get the data I wanted that sent to another file, Here is my code jQuery code:

 <script type="text/javascript"> $(document).ready(function(){ $('#tingkat').change(function(){ $('#unenroll').text(""); var thn_ajar = $("#thn_ajar").val(); var grade = $("#tingkat").val(); alert(grade); // check if there a value alert(thn_ajar); // check if there a value $.ajax({ url : "unenroll.php", type : "get", data : {"thn_ajar": thn_ajar, "grade": grade}, success : function(data){ $("#unenroll").html(data); }, error : function(xhr, teksStatus, kesalahan){ $('#info').html('<b>Terjadi Kesalahan</b>'); } }); // end of $.ajax select unenroll }); // end of $('#tingkat') }); //end of $(document) </script>> 

This one to get the mysql data according parameter I input, I'm using PDO for access the data :

 <?php include"db_connect.php"; try{ $kueri1 = $dt_bas->prepare("SELECT * FROM thn_ajaran ORDER BY tahun_ajaran DESC"); $kueri1->execute(); }catch(PDOException $e){ echo "Error".$e; } try { $kueri2 = $dt_bas->prepare("SELECT * FROM tingkat"); $kueri2->execute(); } catch (PDOException $e) { echo "Error".$e; } ?> <!DOCTYPE html> <html> <head> </head> <body> <form method="get"> <?php $thn_ajar = trim($_GET['thn_ajar']); $grade = trim($_GET['grade']); ?> <table> <?php $thn_ajar = trim($_GET['thn_ajar']); $grade = trim($_GET['grade']); ?> <thead> <th>NI S</th> <th>NAMA SISWA</th> <th>AKSI</th> </thead> <tbody> <?php include "db_connect.php"; try{ $kueri_siswa = $dt_bas->prepare("SELECT z.nis, z.nm_dpn FROM (SELECT h.nis, h.nm_dpn, i.grade FROM siswa h INNER JOIN tingkat i ON h.id_tingkat = i.id_tingkat WHERE i.id_tingkat = :grade AND h.status_siswa ='AKTIF') z LEFT JOIN (SELECT d.nis FROM kelas a INNER JOIN thn_ajaran b ON a.id_thn_ajar = b.id_thn_ajar INNER JOIN siswa_kelas c ON a.id_kelas = c.id_kelas INNER JOIN siswa d ON d.nis = c.nis INNER JOIN tingkat e ON e.id_tingkat = a.id_tingkat WHERE b.tahun_ajaran = :thn_ajar AND e.id_tingkat =:grade2) l ON z.nis = l.nis WHERE l.nis IS NULL"); $kueri_siswa->bindParam(':grade', $grade); $kueri_siswa->bindParam(':thn_ajar', $thn_ajar); $kueri_siswa->bindParam(':grade2', $grade); $kueri_siswa->execute(); }catch(PDOException $le){ echo "Error : $le"; } while ($row = $kueri_siswa->fetch(PDO::FETCH_ASSOC)) { ?> Tabel Row Start ASC <tr> <td><?php echo $row["nis"];?></td> <td><?php echo $row["nm_dpn"];?></td> <td> <a href="#">Ubah<a/> <a href="#">Detail</a> </td> </tr> <?php } ?> </tbody> </table> </form> </body> <html> 

When I check my console, there is no error, but the data I want to show don't show Thank's for your advice and time.

请在ajax中更改data参数的同步文本,以便从变量名中删除双引号。

  data    : {thn_ajar: thn_ajar, grade: grade},

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