0

给定以下jquery

$.post(path, {one:'alex', two:'thomas'}, function (response) {
    alert(response);
});

以及以下PHP

<?php
  $first = $_POST['one'];
  echo $first;
?>

我如何让它返回响应?

如果我只发送一个变量,它工作正常:

$.post(path, 'one=alex', function (response) {
    alert(response);
});

谢谢

4

1 回答 1

3

使用 json。

$response = array(
    'first' => $response1,
    'second' => $response2
);
echo json_encode($response);

$.post(path, 'one=alex', function (response) {
    response = JSON.parse(response );
    alert(response.first);
});
于 2012-08-07T12:39:16.297 回答