您好,我需要知道是否可以在没有表单的情况下进行 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);
}
});
使用 Firebug 进行调试说,有一个带有 ID 和表的 GET 调用,但我没有得到任何返回值(没有 json 也没有 php echo)。
这是我的 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') {
}
}
刚刚使用了一些测试值。
最佳答案
去掉echo('test');
,它不是json。
$.get()
不需要表单。
关于jquery - 没有表格可以打电话吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10806528/