dtncv04228 2012-07-21 16:11
浏览 88
已采纳

通过AJAX从PHP发回多个结果

i have setup some ajax, which i am just testing now, pretty much the idea behind it is to send some data from dropdown boxes to a php script, do some calculations and then return the result, it does it well and returns the result, but now rather than just sending back one result and outputting that, i want to send back multiple results and output them, i am able to send multiple data to the php script, so i am sure i can send multiple back.

Anyway it only sends the first result back and not the rest.

Here is the 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>   

And here is the php script

    <?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));

 ?>

You can see that i have already tried to give it a go from what i thought might work, if you need any other code or want me to remove the code i added which doesn't work, then let me know.

Thanks for all and any help

  • 写回答

2条回答 默认 最新

  • duandanbeng1829 2012-07-21 16:15
    关注

    You're only going to receive one response object:

    function (response) {
        $("#expected_gain").html(response.value);
        $("#house_price").html(response.value2);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表