View unanswered posts | View active topics It is currently Thu Mar 28, 2024 3:03 pm



Reply to topic  [ 1 post ] 
AJAX problems 
Author Message
New pChart user
New pChart user

Joined: Thu Feb 02, 2012 4:17 pm
Posts: 1
Post AJAX problems
Hello there.

I am developing a program in php that accepts some parameters from the client and generates a graph based on them.

How do I do this asynchronously? Maybe this is more an ajax/JS issue but I don't know how to return more than one parameter from the server to the client asynchronously. The idea would be to return text results to some edit buttons and a graph to a <img src> attribute.

Code:
function bbcalc(temperature,lmin,lmax)
{
   
if (temperature==null || lmax==null || lmin==null || temperature=="" || lmax=="" || lmin=="" ||
isNaN(parseFloat(temperature))==1 || isNaN(parseFloat(lmin))==1  || isNaN(parseFloat(lmax))==1 ){
    document.getElementById("error").innerHTML="Por favor, introduzca todos los parĂ¡metros de entrada";
    return 0;
}   
else if ( parseFloat(lmin) >= parseFloat(lmax)){
    document.getElementById("error").innerHTML="El limite inferior tiene que ser menor que el superior";
    return 0;
}
else
    {
   document.getElementById("error").innerHTML="";
    }
    if (document.getElementById("unitselect").selectedIndex==0){ //nm selected. We need to convert units
    lmin=1e7/lmin;
    lmax=1e7/lmax;
} //else, units in cm-1. no need to convert units


if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()
  {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
      document.getElementById("result").value=xmlhttp.responseText;
      }
  }
  xmlhttp.open("GET","bb.php?temp="+temperature+"&lmin="+lmin+"&lmax="+lmax,true);
  xmlhttp.send();

  document.getElementById('grafica').src='mypic.php';

}


Code:
<?php
include("class/pDraw.class.php");
include("class/pImage.class.php");
include("class/pData.class.php");

/* Create your dataset object */
$myData = new pData();

/* Add data in your dataset */
$myData->addPoints(array(VOID,3,4,3,5));

/* Create a pChart object and associate your dataset */
$myPicture = new pImage(700,230,$myData);

/* Choose a nice font */
$myPicture->setFontProperties(array("FontName"=>"fonts/Forgotte.ttf","FontSize"=>11));

/* Define the boundaries of the graph area */
$myPicture->setGraphArea(60,40,670,190);

/* Draw the scale, keep everything automatic */
$myPicture->drawScale();

/* Draw the scale, keep everything automatic */
$myPicture->drawSplineChart();

/* Build the PNG file and send it to the web browser */
$myPicture->stroke();

?>


Thu Feb 02, 2012 4:27 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 3 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