POST to retrieve chart using Ajax
This may be a shot in the dark but I've tried posting to jQuery forums and had no joy. I hope one of you have tried this.
I using jquery and I use the $.ajax function to post my form data to a PHP script that should return an image (not an img tag, but the actual bitstream)
Jquery function:
Code:
function getImage() {
var parameters = "txt="+$('myText').val();
var response = $.ajax({
type: "POST",
url: "myGraph.php?foo=bar,
data: parameters,
dataType: "text",
success: function(imageData) {
$('#chart_image').attr("src","data:image/png;base64,"+imageData);
}
});
}
HTML:
Code:
<html>
<body>
<form method="post">
<input id="myText" name="myText" type="text"/>
</form>
<a href="#" onclick="getImage()">Go get 'er</a>
<div id="chart_holder" /><img src="blank.gif" id="chart_image"/></div>
</body>
</html>
Server side PHP code:
Code:
$graph = new pImage(700,200);
$graph->drawText(10,10,$_POST['txt']);
$graph->stroke();
The issue (I believe) that the the response is interpreted as a text rather than a 64-bit bitstream.
Any ideas?