jquery - 没有表格可以打电话吗?

标签 jquery ajax json

您好,我需要知道是否可以在没有表单的情况下进行 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/

相关文章:

javascript - JS 滚动发生在页面准备好之前

javascript - 动态包含 JavaScript 并等待

ios - 使用 Objective C 解析 JSON 的弹性

jquery - Fancybox v.2.1.2 无法在 IE7 上打开

jquery - 如何将附加数据传递到 ajax post jquery ui 可选择网格 -> fancybox?

java - 如何将 Java 对象序列化为转义 JSON 字符串?

javascript - 我如何在angularjs中格式化json?

php - Ajax /JS : Grabbing multiple input fields without refresh or button click and php echoing the value

javascript - 取消选中复选框时如何禁用提交按钮?

javascript - 我的图像已完成加载,但其高度和宽度尚未更新。这是什么时候发生的?