0

我有一个要发送的表单,目前它使用带有类 .button 的 ap 标签。出于某种原因,我根本没有得到任何回应,也没有在我的 chrome 开发工具的网络选项卡中提交?有什么帮助吗?

$(".button-like").each(function () {
    $(this).click(function () {
        var $thisItem = $(this);
        var $parent = $thisItem.parent(".forms");
        $parent.submit(function () {
            var data = {
                "action": "like"
            };
            data = $parent.serialize() + "&" + $.param(data);
            var itemId = $parent.find('input.id').val();
            $.ajax({
                type: "POST",
                url: "/actions/",
                data: data,
                success: function (data) {
                    console.log('Like submitted successfully sent');
                    $('body').addClass('liked');
                }
            });
            return false;
        });
    });
});

谢谢,马克

4

1 回答 1

0
$(".button-like").each(function () {
    $(this).click(function () {
        var $thisItem = $(this);
        var $parent = $thisItem.parent(".forms");
        $parent.submit(function () {
            var data = {
                "action": "like"
            };
            data = $parent.serialize() + "&" + $.param(data);
            var itemId = $parent.find('input.id').val();
            $.ajax({
                type: "POST",
                url: "/actions/",
                data: data,
                success: function (data) {
                    console.log('Like submitted successfully sent');
                    $('body').addClass('liked');
                }
            });
            return false;
        }).submit();
    });
});

这将在设置后立即触发提交。但我认为你想要做的是:

$(".button-like").each(function () {
    var $thisItem = $(this);
    var $parent = $thisItem.parent(".forms");
    $parent.submit(function () {
        var data = {
            "action": "like"
        };
        data = $parent.serialize() + "&" + $.param(data);
        var itemId = $parent.find('input.id').val();
        $.ajax({
            type: "POST",
            url: "/actions/",
            data: data,
            success: function (data) {
                console.log('Like submitted successfully sent');
                $('body').addClass('liked');
            }
        });
        return false;
    });
    $thisItem.click(function () {
        $parent.submit();
    });
});
于 2013-08-08T22:15:19.333 回答