Choose a file to view:
index.php
json_query.php
or go back to the demo
<!DOCTYPE html> <html> <head> <title>JSON Demo</title> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> <script> $(function(){ $('.requestBtn').on('click',function(){ var id = $(this).attr('id'); var result = ""; $.when( getTable(id)).done(function( data ) { var result = $.parseJSON(data); displayTable(result); }); }); function getTable(_id) { return $.post( "json_query.php", {listType: _id} ); } function displayTable(result) { var tableHTML = "<table border='1'>"; tableHTML += "<tr><td>First Name</td><td>Last Name</td><td>Certification Date</td><td>Advanced Crtification Date</td></tr>"; $.each(result, function( index, value ) { if(value.error == null) { tableHTML += "<tr><td>"+value.fname+"</td><td>"+value.lname+"</td><td>"+value.cert_date+"</td><td>"+(value.advanced_cert_date != null ? value.advanced_cert_date : '')+"</td></tr>"; } else { tableHTML += "<tr><td colspan='4'>"+value.error+"</td></tr>"; } }); tableHTML += "<table>"; $("#resultsTable").html(tableHTML); } }); </script> </head> <body> <div>Click a button to request data:</div> <button type="button" class="requestBtn" id="name">Order By Name</button> <button type="button" class="requestBtn" id="cert_date">Order By Certification Date</button> <div id="resultsTable"></div> <p><a href="../index.php">[Back to demos home]</a> <a href="fileView.php">[View source code]</a></p> </body> </html>