I currently use this to to open new content in a div (so I don’t have to refresh the whole page):
file1.php
<?php
//db connection
if ($res = $mysqli->query("SELECT field FROM table")) {
/* determine number of rows result set */
$row = $res->num_rows;
echo "$row";
$res->close();
}
?>
jquery.js
$.ajax({
url: "file1.php",
//this will run as soon as the php script echos the answer
success: function(result){
$('#div1').html(result);
}
});
page1.php
<div id="div1">
</div>
Code Updated
From your comments i understand you are a bit confused, so i’ll do my best to explain:
somePage.php:
jquery:
Of course you’ll need a button in your HTML:
this is roughly how you do it. I suggest you take a look at jquery.ajax(), it is not that hard.