2012-05-29 127 views
1

您好我需要知道是否有可能沒有窗體有一個Ajax GET調用。無法獲得呼叫嗎?

我想:

$(".edit_event").live("click", function() { 
    var currentID = $(this).data("event-id"); 
    var currentTable = $(this).data("table"); 

    if (currentTable == 'Coffee_talk') { 
     alert('Erzaehlcafe mit ID' + currentID); 

     $.ajax({ 
      url: 'index.php?section=event_select&id=' + currentID + '&table=' + currentTable, 
      type: 'GET', 
      dataType: 'json', 
      success: function (select) { 
       alert(select); 
      } 
     }); 
     return false; 
    } else if (currentTable == 'Presentation') { 
     alert('Vortrag mit ID' + currentID); 
    } else if (currentTable == 'Exhibition') { 
     alert('Ausstellung mit ID' + currentID); 
    } 
}); 

調試與螢火蟲說,有一個GET調用與ID和表,但我沒有得到任何值回(無JSON也不是PHP的回聲)。

這是我的PHP:

if ('GET' == $_SERVER['REQUEST_METHOD']) { 
    if ($_GET['table'] == 'Coffee_talk') { 
     echo ('test'); 

     $response['code'] = '1'; 
     echo json_encode($response); 
    } 
    if ($_GET['table'] == 'Presentation') { 

    } 
    if ($_GET['table'] == 'Exhibition') { 

    } 
} 

只是使用了一些測試值。

+0

[堆棧溢出不需要你的搜索引擎優化技巧](http://meta.stackexchange.com/a/130208/143302) – Filburt

回答

3

擺脫echo ('test');,它不是json。

$.get()不需要表單。

+0

thx刪除回聲陳述。使用以下代碼:'$獲得( 「?的index.php部= event_select&ID =」 + currentID + 「&表=」 + currentTable, \t \t \t \t功能(數據){ \t \t \t \t \t警報(數據); \t \t \t \t},「json」); \t \t \t return false;'但是我沒有得到JSON。 – JPM

+0

你會得到'[object object]'嗎? –

+0

好的,sry發現了這個bug。我想使用event_edit部分,但在編碼時我傾向於使用event_select並且沒有定義新的部分..它的工作現在thx;) – JPM