当我在 Chrome 检查器中查看 test.php 发送的标头时,它说action : startjson
但我无法检索此变量$_GET['action']
,数组为空。
测试.php:
<body>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script language="JavaScript">
$(document).ready(function(){
$("#testjson").click(function(e){
startJsonSession();
return false;
});
function startJsonSession(){
$.ajax({
url: "test2.php?action=startjson",
cache: false,
dataType: "json",
complete: function(data) {
username = data.username;
alert(username);
}
});
}
});
</script>
<button id="testjson">
toto
</button>
</body>
测试2.php:
<?php
if ($_GET['action'] == "startjson") {
startjsonSession();
}
function startjsonSession() {
$items = '';
print json_encode(array(
"username" => "bob",
"items" => array(
"item1" => "sandwich",
"item2" => "applejuice"
)
));
}