I have the following jQuery code to execute when I click a button
$('#substat').click(function() {
$.post('ext/engine.php', post, function(data){
$('#statout').empty().append(data).dialog(
{height:350, width:700, dialogClass: 'shadowme', position: 'center'})
});
});
UPDATE – I have checked code by code to see where the problem is. As it looks, it is the PHP part which looks like this:
$html = '<script>';
for($s = 0; $s < $m; $s++) {
if ($m-$s != 1) { $var1 .= $out[total][$s].', '; $var2 .= $out[age][$s].'", "'; }
else { $var1 .= $out[total][$s]; $var2 .= $out[age][$s].'"';}
if ($out[total][$s] > $max) { $max = $out[total][$s]; }
}
if ($max > 10) { $max = round($max/10); }
$html .= 'VarH = ['.$var1.'];
plot1 = $.jqplot("statout", [VarH], {
legend:{show:true, location:"ne"},
title:"Gente",
series:[ { label:"VarH", renderer:$.jqplot.BarRenderer } ],
axes:{
xaxis:{ renderer:$.jqplot.CategoryAxisRenderer, ticks:['.$var2.'] },
yaxis:{ min:0, tickInterval:'.$max.', autoscale: true }
},
seriesDefaults:{ lineWidth:5, rendererOptions: { barWidth:5, barMargin:5, barPadding:0 } }
});
</script>';
echo $html;
If i change the last line from echo $html; to echo “Hello”; it will always work.
But if i leave it with the $html variable created with jqplot it will only work one time when rendered inside the jquery dialog. After that I have to refresg the webpage to make it work again instead of just clicking again on the submit button to create the dialog with the graph in it.
I had the same problem. The solution is to display the dialog first and afterwards (!) load the chart into.