duanchongzi9997
duanchongzi9997
2015-12-29 23:11

UNDEFINED - PHP与jQuery AJAX的多个返回值

  • php
  • ajax
  • javascript

Because I get undefined. Where I am failing?

Code:


    function add(id,cost){
            var info = {
                    "id" : id,
                    "cost": cost,
            };
            $.ajax({
                    data:  info,
                    url:   'a.php',
                    type:  'post',
                    success:  function (datos) {
                             alert(datos+"
 r1: "+datos.r1+"
 r2:"+datos.r2);
                    }
            });
    }

archive a.php PHP:


    $cost=$_POST['id']*$_POST['cost'] + 137;
    echo json_encode(array("r1" =>$_POST['id'], "r2" => $cost));

image

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换