2013-10-18 2 views
0

크롬 관리자의 test.php에서 보낸 헤더를 보면 action : startjson이라고 표시되지만이 변수를 검색 할 수 없습니다. $_GET['action'], 배열이 비어 있습니다.Get ajax가 작동하지 않는다

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> 

test2.php :

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

     function startjsonSession() { 
      $items = ''; 

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

요청 상태는 어떻습니까? – tymeJV

답변

1

성공하고 완전한 차이가있다는 '데이터'매개 변수를 수신, 그렇다면하지 않습니다 완성 기능 액션 데이터에 따라 다르면 작동하지 않습니다.

완료 : 요청이 완료되면 실패 또는 성공 여부에 상관없이 전체 콜백 옵션이 실행됩니다. jqXHR 객체와 성공 또는 에러 코드를 포함하는 문자열을 수신합니다.

성공 : 요청이 성공하면 콜백 옵션이 호출됩니다. 반환 된 데이터, 성공 코드를 포함하는 문자열 및 jqXHR 객체를 수신합니다.

관련 문제