Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay... so I sort of know JQuery and that is easiest for me. Take a look at this example. It is self contained. Really, you can name the HTML page whatever you want. The other page does need to be called <code>get_words.php</code> so that the ajax will work. Each time the ajax is ran, it makes a dump to the <code>console.log()</code> so you can see what is going on. </p> <p><strong>show_words.html</strong> - this page is the one that displays stuff. it makes an ajax call to <code>get_words.php</code> in both an html format and a json format. </p> <pre><code>&lt;script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"&gt;&lt;/script&gt;) &lt;style&gt; table.word_list {border: 1px solid #C0C0C0; border-collapse:collapse; width:400px} table.word_list th, td {border: 1px solid #C0C0C0; margin:2px; padding-right:10px; padding-left:4px;} &lt;/style&gt; &lt;button id="more_words_table" type="button"&gt;More Words! (table)&lt;/button&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;button id="more_words_json" type="button"&gt;More Words! (json)&lt;/button&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;div id="counter" style="display:inline-block"&gt;&lt;/div&gt; &lt;table id="tbl_word_list" class='word_list'&gt; &lt;tr&gt; &lt;th style="width:30%"&gt;Word&lt;/th&gt; &lt;th&gt;Meaning&lt;/th&gt; &lt;/tr&gt; &lt;tbody&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;script&gt; $(document).ready(function(){ var word_count = 0; var more_words = true; $("#more_words_json").on("click",function(){ if (more_words===false) return; var request = $.ajax({ type: "POST", url: "get_words.php", data: { "offset" : word_count, "limit" : 5, "return" : "json"}, dataType: "json" }); request.done(function(data){ console.log(data); if (data.length!==0) { word_count+=5; $.each(data, function(i,item){ $("#tbl_word_list").append("&lt;tr&gt;&lt;td&gt;"+item.word+"&lt;/td&gt;"+ "&lt;td&gt;"+item.meaning+"&lt;/td&gt;&lt;/tr&gt;"); }); update_counter(); } else { no_more_words(); } }); }); $("#more_words_table").on("click",function(){ if (more_words===false) return; var request = $.ajax({ type: "POST", url: "get_words.php", data: { "offset" : word_count, "limit" : 5, "return" : "table"}, dataType: "html" }); request.done(function(data){ console.log(data); if (data.length!==0) { word_count+=5; $("#tbl_word_list").append(data); update_counter(); } else { no_more_words(); } }); }); function update_counter() { $("#counter").html(word_count+" words displayed"); } function no_more_words() { more_words = false; $("#counter").html("No more words available!"); } }); &lt;/script&gt; </code></pre> <p><strong>get_words.php</strong> - this page takes some <code>$_POST</code> values and then prints some data that will be retrieved by the ajax call on the main page. </p> <pre><code>&lt;?php $word_list = array("Amorphous: indefinite, shapeless", "Beguile: deceive", "Caprice: impulse", "Cascade: steep waterfall", "Cashmere: fine, delicate wool", "Chrysalis: protective covering", "Cinnamon: an aromatic spice; its soft brown color", "Coalesce: unite, or fuse", "Crepuscular: dim, or twilit", "Crystalline: clear, or sparkling", "Desultory: half-hearted, meandering", "Diaphanous: gauzy", "Dulcet: sweet", "Ebullient: enthusiastic", "Effervescent: bubbly", "Elision: omission", "Enchanted: charmed", "Encompass: surround", "Enrapture: delighted", "Ephemeral: fleeting", "Epiphany: revelation", "Epitome: embodiment of the ideal", "Ethereal: celestial, unworldly, immaterial", "Etiquette: proper conduct", "Evanescent: fleeting", "Evocative: suggestive", "Exuberant: abundant, unrestrained, outsize", "Felicity: happiness, pleasantness", "Filament: thread, strand", "Halcyon: care-free", "Idyllic: contentedly pleasing", "Incorporeal: without form", "Incandescent: glowing, radiant, brilliant, zealous", "Ineffable: indescribable, unspeakable", "Inexorable: relentless", "Insouciance: nonchalance", "Iridescent: luster", "Languid: slow, listless", "Lassitude: fatigue", "Lilt: cheerful or buoyant song or movement", "Lithe: flexible, graceful", "Lullaby: soothing song", "Luminescence: dim chemical or organic light", "Mellifluous: smooth, sweet", "Mist: cloudy moisture, or similar literal or virtual obstacle", "Murmur: soothing sound", "Myriad: great number", "Nebulous: indistinct", "Opulent: ostentatious", "Penumbra: shade, shroud, fringe", "Plethora: abundance", "Quiescent: peaceful", "Quintessential: most purely representative or typical", "Radiant: glowing", "Redolent: aromatic, evocative", "Resonant: echoing, evocative", "Resplendent: shining", "Rhapsodic: intensely emotional", "Sapphire: rich, deep bluish purple", "Scintilla: trace", "Serendipitous: chance", "Serene: peaceful", "Somnolent: drowsy, sleep inducing", "Sonorous: loud, impressive, imposing", "Spherical: ball-like, globular", "Sublime: exalted, transcendent", "Succulent: juicy, tasty, rich", "Suffuse: flushed, full", "Susurration: whispering", "Symphony: harmonious assemblage", "Talisman: charm, magical device", "Tessellated: checkered in pattern", "Tranquility: peacefulness", "Vestige: trace", "Zenith: highest point",); $offset = (isset($_POST['offset'])) ? $_POST['offset'] : 0; $limit = (isset($_POST['limit'])) ? $_POST['limit'] : 5; $return = (isset($_POST['return'])) ? $_POST['return'] : 'table'; // no more words... return empty json or nothing depending on the return type if ($offset&gt;=count($word_list)) { if ($return=="json") { print "[]"; } exit(); } $subset = array_slice($word_list,$offset,$limit); if ($return == 'json') { $data = array(); foreach ($subset as $i =&gt; $item) { list($word, $meaning) = explode(':',$item); $data[] = array('word' =&gt; $word, 'meaning' =&gt; $meaning); } print json_encode($data); } else if ($return == 'table') { foreach ($subset as $i =&gt; $item) { list($word, $meaning) = explode(':',$item); print "&lt;tr&gt;&lt;td&gt;{$word}&lt;/td&gt;&lt;td&gt;{$meaning}&lt;/td&gt;&lt;/tr&gt;"; } } ?&gt; </code></pre>
    singulars
    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