Ok guys/Gals. I need some help. Or a better way to do this. I need to be make it when someone clicks div id O+$row['Id'] will load the function displayops and some how pass the arguments. I can deal with the $row['name'] not being passed, and $pastOp will always = TRUE in this case. And I need to do it without reloading the page if at all possible.
The reason I need this is because running it for ALL of them at the same time takes almost 5-10 min for it to load completely, and there is no need to load all of them. Just the ones that people need to click on as they go. Any help is truly appreciated.
while($row = $result->fetch_assoc()){
echo "<div style=\"clear: both;\"></div>\n";
echo "<div class=\"operation\">\n";
echo "<h2 class=\"opsList\" style=\"cursor:pointer;\"><img src=\"/js/assets/".$row['icon']."\"/><div id=\"O".$row['Id']."\">Past Operations for " .$row['Name'] ."</div></h2>\n";
echo "<div class=\"initiallyHidden\" id=\"P".$row['Id']."\">";
// displayops($row['Id'], $row['Name'], $pastOp);
echo "</div>";
echo "</div>\n";
}
Using a modified version of Adams code and some research online I got it to work. (THANK YOU ADAM!!!) Below is the modified Jquery
Ok, I was able to takes Some of Adams code and make it work. Thank you very much Adam. Below is what worked.
$(document).ready(function(){
$(function(){
$('.operation').click(function(){
var container = $(this);
var params = {
id: $(this).data('id'),
name: $(this).data('name')
};
$
$.ajax({
url: '/opserv/ajaxExPrintOps.php',
data: params,
type: 'POST',
dataType: 'html',
success: function(data){
$('.initiallyHidden', container).html(data);
},
error: function(){
alert('An error occurred'); //Or something mroe useful?
}
});
});
});
});
JSONfrom the PHP output, rather then using PHP to render the output. This is proper separation of concerns and cleaner. see fiddle