calculate.php
<form method="post" name="frm_deptcal" id="frm_deptcal" action="javascript:add(document.getElementById('frm_deptcal'));" >
<span style="font-weight:bold;">Enter your total unsecured* debt </span>
<input type="text" name="txt_principal" id="txt_principal" / >
<input type="submit" name="button" value="Calculate" style="background: none repeat scroll 0% 0% rgb(51, 136, 180); color: white; border: 5px solid rgb(120, 176, 205); cursor: pointer;">
</form>
在ajax_cal.js中我有add(),其中创建XMLHttpRequestObject并发送字符串
代码:
var str1= "txt_principal=" + document.getElementById("txt_principal").value;
XMLHttpRequestObject.onreadystatechange = show;
XMLHttpRequestObject.open('POST', 'value.php', true);
XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
XMLHttpRequestObject.send(str1);
在value.php中我做了计算:
$principal=$_POST['txt_principal'];
$x=0.3;
$consumer_mon_pay=60;
$mp_consumer_ans=($principal * $x)/$consumer_mon_pay;
$mp_consumer=round($mp_consumer_ans,3) ;
echo $mp_repay."[BRK]".$mp_conloan."[BRK]".$mp_credit."[BRK]".$mp_consumer;
在ajax_cal.js中我得到了html的回复并在文本框中显示
function show()
{
if (XMLHttpRequestObject.readyState == 4)
{
if (XMLHttpRequestObject.status == 200)
{
data = XMLHttpRequestObject.responseText.split("[BRK]");
document.getElementById('txt_mp_repay').innerHTML = data[0];
document.getElementById('txt_mp_conloan').innerHTML = data[1];
document.getElementById('txt_mp_credit').innerHTML = data[2];
document.getElementById('txt_mp_consumer').innerHTML = data[3];
}
}
}
现在我的问题是我必须绘制一个动态图形,其x轴应该是(txt_mp_repay,txt_mp_conloan,txt_mp_credit,txt_mp_consumer)值,而y轴将是txt_mp_repay值。条形图编码使用open-flash完成chart-data.php中的图表,我通过它创建了一个静态图形。问题是如何将响应发送到chart-data.php并在calculate .php页面上显示整个内容。帮帮我......谢谢
答案 0 :(得分:0)
我有点不清楚你想做什么,但没有什么能阻止你同时发出两个ajax请求。像
var str1= "txt_principal=" + document.getElementById("txt_principal").value;
XMLHttpRequestObject.onreadystatechange = show;
XMLHttpRequestObject.open('POST', 'value.php', true);
XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
XMLHttpRequestObject.send(str1);
XMLHttpRequestObject.open('POST', 'chart.php', true);
XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
XMLHttpRequestObject.send(str1);