View unanswered posts | View active topics It is currently Mon May 13, 2024 5:02 pm



Reply to topic  [ 1 post ] 
POST to retrieve chart using Ajax 
Author Message
Experienced pChart user
Experienced pChart user

Joined: Wed Dec 22, 2010 9:00 pm
Posts: 30
Post 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?


Sat Jun 04, 2011 2:00 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron