javascript - onClick refresh a div with random line of text from "quotes.txt" -


i have quote generator @ http://communitychessclub.com. want user able click on quote , load random quote w/o refreshing entire page. how can this?

<h3>  <?php $randomthings = file('quotes.txt', file_ignore_new_lines | file_skip_empty_lines);  echo $randomthings[mt_rand(0,count($randomthings)-1)];?>  </h3> 

i tried colin shoens suggestion below with:

<div id="new-projects"></div> <script> $( "#new-projects" ).load( "quotes.txt" ); </script> 

but loaded 307 quotes instead of single random quote.

http://communitychessclub.com/test.php

how can fix this?

you mentioned have on 300 quotes, inline js array of quotes on client-side page not efficient. here's quick solution using jquery , php:

php - quotes.php

<?php      // original php code,     $randomthings = file('quotes.txt', file_ignore_new_lines | file_skip_empty_lines);      echo $randomthings[mt_rand(0,count($randomthings)-1)]; ?> 

html side

<h3 id="new-projects"></h3> <script>     $( "#new-projects" ).on("click", function(){        $(this).load( "quotes.php" );     }); </script> 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -