Jquery Can';我无法让ajax正常工作

Jquery Can';我无法让ajax正常工作,jquery,ajax,get,Jquery,Ajax,Get,当我在Chrome inspector中查看test.php发送的头时,它显示action:startjson,但我无法检索此变量$\u GET['action'],数组为空 test.php: <body> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script language="JavaScript"> $(document).re

当我在Chrome inspector中查看test.php发送的头时,它显示
action:startjson
,但我无法检索此变量
$\u GET['action']
,数组为空

test.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>

$(文档).ready(函数(){
$(“#testjson”)。单击(函数(e){
startJsonSession();
返回false;
});
函数startJsonSession(){
$.ajax({
url:“test2.php?action=startjson”,
cache:false,
数据类型:“json”,
完成:功能(数据){
用户名=data.username;
警报(用户名);
}
});
}
}); 
托托
test2.php:

    <?php 
    if ($_GET['action'] == "startjson") { 
            startjsonSession(); 
        } 

        function startjsonSession() {
            $items = '';

            print json_encode(array(
                "username" => "bob",
                "items" => array(
                    "item1" => "sandwich",
                    "item2" => "applejuice"
                )
            ));
        }

success和complete之间有区别,complete函数不接收“data”参数,因此如果您的操作依赖于数据,那么它在那里将不起作用

Complete:当请求完成时,无论是失败还是成功,都会触发Complete回调选项。它接收jqXHR对象以及包含成功或错误代码的字符串


成功:如果请求成功,则调用回调选项。它接收返回的数据、包含成功代码的字符串和jqXHR对象。

请求的状态如何?