Refreshing a div tag to change results

I found a script that refreshes a div tag but it only works half way. I have a php if statement in the middle of the script and based on the if decision it should display the appropriate information.
if no click display " button not pressed"
echo random number

the first part works but not the sec. part.
any ideas as to how i can fix this.?

		<meta charset="ISO-8859-1">
		<script src=""></script>
		$(document).ready(function() {
			$('#btn_click').on('click', function() {
				var url = 'refreshDiv.php';
				$('#div1-wrapper').load(url + ' #div1');
<?php echo rand(10,1000); // test outside the div container?>
	<div id="div1-wrapper">
		<div id="div1"  style="border:solid 2px red; width: 200px;">
			<form name="form1" method="POST">
					{ 	echo 'button not pressed'; }
					 {	echo rand(10,1000); } 			
	 <button type="button"  id="btn_click" /> click me! </button> 			

Currently you are checking if the form has been posted:


But instead of posting the form, you are loading a new page.

$('#div1-wrapper').load(url + ' #div1');

So don’t do that. Get rid of all the scripting - you don’t need it for what you’re doing here.

Instead of scripting, give the button a name and a value so that the empty() check will find something, and things will work as desired.

<button type="submit"  name="btn_click" value="submitted" /> click me! </button>           

Alternatively, you can get away with no value by using another technique to check if btn_click exists, by using filter_has_var, that lets you easily check for such things:

if(!filter_has_var(INPUT_POST, "btn_click"))

<button type="submit"  name="btn_click" /> click me! </button>