2012-05-29 79 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