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