如何通過JavaScript腳本請求PHP頁面並將數據傳遞給它?那麼我該如何讓PHP腳本將數據傳回給JavaScript腳本呢?如何將數據從Javascript傳遞到PHP,反之亦然?
client.js:
data = {tohex: 4919, sum: [1, 3, 5]};
// how would this script pass data to server.php and access the response?
server.php:
$tohex = ... ; // How would this be set to data.tohex?
$sum = ...; // How would this be set to data.sum?
// How would this be sent to client.js?
array(base_convert($tohex, 16), array_sum($sum))
值得注意的是,它僅適用於相對URL,因爲同源策略:http://en.wikipedia.org/wiki/Same-origin_policy – 2014-10-15 14:03:19