Sometimes I use the jQuery load() function to display dynamic content inside html elements. As the description says:
load() Description: Load data from the server and place the returned HTML into the matched element.
I provided a working example that loads a simple html file with html tags and another php files that contains variables.
Here is the jQuery code:
1 2 3 4 5 6 7 8 9 10 11 |
$(document).ready(function() { $(".click-html").on('click', function() { $( ".load-html" ).load( "load.html" ); }); $(".click-php").on('click', function() { $(".load-php").load("click.php?var1=var1value&var2=var2value"); }); }); |
Here is the PHP code that deals with the two variables:
1 2 3 4 5 6 7 8 |
<?php echo $_GET["var1"]; echo "<br>"; echo $_GET["var2"]; if($_GET["var2"] == "var2value") { echo "<hr>"; } ?> |