jQuery Popup Save按钮执行POST方法

时间:2015-12-07 08:07:25

标签: jquery asp.net-mvc asp.net-mvc-5

我使用下面的代码打开一个包含文本框的jQuery弹出框。

用户必须填写备注并单击弹出窗口中的“保存”按钮。

弹出窗口有两个按钮:保存和取消。

我在单击Save时尝试调用Action方法,但每次调用GET方法时都是如此。它没有调用POST方法。

点击“保存”后,输入的备注应发布到“操作方法”。

此代码需要进行哪些更改?

<script type="text/javascript">
        $(function () {
        $('#btnclick').click(function () {
            $("#popupdiv").dialog({
                title: "Enter Remarks: ",
                width: 400,
                height: 200,
                modal: true,
                buttons: {
                    Save: function () {
                        //POST code here
                    },
                    Close: function () {
                        $(this).dialog('close');
                    }
                }
            });
        });
    })
    </script>

1 个答案:

答案 0 :(得分:2)

这是一个ajax帖子的例子。假设您的评论包含在moment(yourDate).format("YYYY-MM-DD HH:mm:ss"); 中,您可以尝试此操作。

$('#remarks')

并且您的操作结果将类似于此

var remarks = {remarks: $('#remarks').val()};
var json = JSON.stringify(remarks);
 $.ajax({
        url: "localhost/Home/RemarksPost",
        type: "post",
        data:  json,
        dataType: 'json',
        success: function (response) {
           // you will get response 

        },
        error: function(jqXHR, textStatus, errorThrown) {
           console.log(textStatus, errorThrown);
        }


    });