我已经设置了一些ajax,我现在只是测试它,其背后的想法很多是将一些数据从下拉框发送到一个php脚本,做一些计算然后返回结果,它做得很好,并返回结果,但现在,而不是只发回一个结果和输出,我想发回多个结果并输出它们,我能够发送多个数据到php脚本,所以我是当然我可以发送多个回来。通过AJAX通过PHP发送多个结果
无论如何,它只发回第一个结果,而不是其余。
这里是AJAX
<script>
$("document").ready(function(){
$(".add_extension").change(function(){
var m = document.getElementById('meter_square');
var meter_square = m.options[m.selectedIndex].value;
var s = document.getElementById('story_height');
var story_height = s.options[s.selectedIndex].value;
$.ajax({
type: "GET",
url: "script.php",
data: { meter_square: meter_square, story_height: story_height },
dataType: "json",
statusCode: {
200: function (result, result2)
{
$("#expected_gain").html(result.value);
$("#house_price").html(result2.value2);
}
}
});
})
});
</script>
,这里是PHP脚本
<?php
$meter_square = $_GET["meter_square"];
$story_height = $_GET["story_height"];
$result = $meter_square + $story_height;
$result2 = $meter_square * $story_height;
echo json_encode(array("value" => $result, "value2" => $result2));
?>
你可以看到,我已经尝试给它从我的想法可能会奏效,如果去你需要任何其他代码或要我删除我添加的代码不起作用,然后让我知道。
感谢所有和任何帮助
为什么你需要做加法和乘法在PHP? JS是完全有能力的 – Martin 2012-07-21 16:14:07
我只是使用它作为测试部分来让ajax首先工作,php脚本将会非常大,所以我在 – Arken 2012-07-21 16:17:18
之后就可以了,只需检查一下;)我看到你已经有了它解决了反正:) – Martin 2012-07-21 17:01:47