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 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入