User Tools

Site Tools


php_jquery_ajax

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
php_jquery_ajax [2016/05/23 11:25]
mh
php_jquery_ajax [2016/05/23 11:27] (current)
mh
Line 50: Line 50:
 <​html>​ <​html>​
 </​code>​ </​code>​
 +
 +Oder die Trennung von Pr√§sentation und Datengenerierung
 +
 +php, liefert JSON
 +list-persons-ajax.php
 +<​code>​
 +<?php
 +require('​db.php'​);​
 +$dbh = get_db();
 +$person_list = 
 +  $dbh->​query('​select fullname, birthdate, country_code from person'​)
 +      ->​fetch_all(MYSQLI_ASSOC);​   ​
 +   ​
 +header('​Content-type:​ application/​json'​);​
 +echo json_encode($person_list); ​
 +</​code>​
 +
 +welches dann mit jquery get abgefragt und danach formatiert angezeigt wird
 +<​code>​
 +<​html>​
 +<script src="​https://​code.jquery.com/​jquery-2.2.0.min.js"></​script>​
 +
 +<div id='​liclass'>​
 +</​div>​
 +<​script>​
 +$(document).ready(function() {
 +var ret = $.get("/​kurs/​list-persons-ajax.php"​) ​  
 +  .done(function( person_list) {    ​
 +    $.each( person_list,​ function( key, person ) {
 +      $('#​liclass'​).append("<​li>"​+ ​ person['​fullname'​] +"</​li"​ );
 + });  ​
 +  });
 +});
 +</​script>​
 +</​html>​
 +</​code>​
 +
php_jquery_ajax.txt · Last modified: 2016/05/23 11:27 by mh