Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is an example which uses a favorite jQuery plugin of mine, <a href="http://api.jquery.com/jquery.tmpl/" rel="nofollow">jQuery.tmpl()</a>, and also the jQuery <a href="http://api.jquery.com/text/" rel="nofollow">.text()</a> function.</p> <p>HTML and Javascript Code:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt; &lt;script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;script id="UserTemplate" type="text/x-jquery-tmpl"&gt; &lt;li&gt;&lt;b&gt;Username: ${name}&lt;/b&gt; Group ID: (${group_id})&lt;/li&gt; &lt;/script&gt; &lt;button id="facebookBtn"&gt;Facebook Button&lt;/button&gt; &lt;div id="UserCount"&gt;&lt;/div&gt; &lt;ul id="userList"&gt;&lt;/ul&gt; &lt;script&gt; function getData(group_id) { $.ajax({ dataType: "json", url: "test.php?group_id=" + group_id, success: function( data ) { var users = data.users; /* Remove current set of movie template items */ $( "#userList" ).empty(); /* Render the template with the movies data and insert the rendered HTML under the "movieList" element */ $( "#UserTemplate" ).tmpl( users ) .appendTo( "#userList" ); $( "#UserCount" ).text('Number of users: '+ data.count); } }); } $( "#facebookBtn" ).click( function() { getData("1"); }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>PHP Code</p> <pre><code>&lt;?php //Perform a query using the data passed via ajax $group_id = $_GET['group_id']; $user_array = array( array('name'=&gt;'John','group_id'=&gt;'1',), array('name'=&gt;'Bob','group_id'=&gt;'1',), array('name'=&gt;'Dan','group_id'=&gt;'1',), ); $user_count = count($user_array); echo json_encode(array('count'=&gt;$user_count,'users'=&gt;$user_array)); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload