如何将输入数据字段的值发送到ajax文件并在数据库中更新

时间:2016-12-05 11:18:55

标签: php jquery ajax

我想发送data-statusdata-id以使用这些值更新数据库中的注释表。是否可以在没有表单的情况下将此值发送到ajax文件?

<?php $status = ($row['comment_status'] == '1') ? "Hide" : "Show"; ?>                                                
<p>
    <input type="submit" name="submit" id="btn1" class="pull-right btn <?php if ($row['comment_status'] == '1') echo "btn-success"; else echo "btn-danger"; ?>" value="<?=$status?>" data-status="<?=$row['comment_status']?>" data-id="<?=$row['comment_id']?>"/>
</p>
$.ajax({
    alert();
    type: "POST",
    url: 'ajax-commentstatus.php',
    data: {
        status: $(this).attr('data-status'),
        comment_id: $(this).attr('data-id'),
    },
    dataType: 'html'
    success: function(data) {
        $("#msg").fadeIn().html(data);
        setTimeOut(function({
            $("#msg").fadeOut('slow');
        }, 2000);
        )
    }
});

0 个答案:

没有答案