The user will enter some dimensions, click a button and see an image created with PHP (without a page refresh). The code I have so far is not putting the image on the page, any idea would be greatly appreciated.
draw.html:
<html>
<head>
<title>PHP Draw Test</title>
<script src = "http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src = "draw.js"></script>
</head>
<body>
<h1>Test the PHP GD module</h1>
<div>
<label>Height:</label>
<input type="number" id="height" min=36 max=42 step=6 required />
<label>Width:</label>
<input type="number" id="width" value="50"/>
<button id="SubmitRailing" type="button">Draw!</button>
<button type="reset">Reset</button>
</div>
<div id="DrawBox"></div>
</body>
</html>
draw.js:
$(document).ready(function() {
$('#SubmitRailing').click(function(){
$.post("draw.php",
{Height: $('#Height').val(), Width: $('#Width').val()},
function(data){
$('#DrawBox').html(data);
}
);
});
});
draw.php:
<?php
$height = $_POST['Height'];
$width = $_POST['Width'];
$im = imagecreatetruecolor($width, $height);
$sand = imagecolorallocate($im, 222, 184, 135);
$white = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $white);
imagecolortransparent($im, $white);
imagefilledrectangle($im, 4, 4, 50, 25, $sand);
imagepng($im, './drawtest.png');
imagedestroy($im);
echo '<img src="drawtest.png" />';
?>
UPDATE syntax syntax syntax I finally got this to work, modified from @gibberish example
data: { Height : Height, Width : Width},
success: function(data) {alert('This was sent back: ' + data);}
But when I tried to substitute my original statement:
function(data){$('#DrawBox').html(data);}
it would kill the script. Finally this worked, I didn't think it should be neccessary but there you have it:
success: function(data){$('#DrawBox').html(data);}