Non so se intendi una cosa del genere.
Il file test9347a.php serve solo per mostrare il rinvio di valori da php a ajax.
codice HTML:
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
function pippo() {
document.getElementById('miodiv').style.display = 'block';
var res = Math.random();
$.ajax({
url : 'test9347a.php',
type : 'POST',
data : {'r' : res},
dataType : 'html'
}).done(function(html) {$('#miodiv').html(html)}) ;
}
</script>
</head>
<body>
<input type="button" value="Clicca" onclick="pippo()"/>
<div id="miodiv" style='display:none'>
</div>
</body>
</html>
test9347a.php
Codice PHP:
<?php
print rand ( 0 , 1000 );