【问题标题】:How to fix this js script to send a value by method post如何修复此 js 脚本以通过方法 post 发送值
【发布时间】:2013-05-14 09:31:34
【问题描述】:

我有这个 Javascript,我想点击确定并在我的控制器中调用 detel 方法, 但它不工作,我不知道为什么。

我需要在此提交中输入两个值:
id and name。

我也不知道应该是什么网址,因为方法没有改变。我现在正在删除,但在 get 方法中。

代码如下:

<script type="text/javascript">
    $(function () {
        $("#dialog-confirm").dialog({
            resizable: false,
            height: 140,
            modal: true,
            buttons: {
                "Ok": function () {
                    $.ajax({
                        type: "POST",
                        url: "",
                        data: { name: ViewBag.ProductName, id: ViewBag.ProductID },
                        success: function () {
                            alert("succes");
                            $("#result").html('submitted successfully');

                        },
                        error: function () {
                            alert("failure");
                            $("#result").html("there is error with submit");
                        }
                    })
                    $(this).dialog("close");
                },
                Anuluj: function () {
                    $(this).dialog("close");
                }
            }
        });
    });
  </script>

【问题讨论】:

  • “Anuluj”是什么意思?
  • 意思是cancle。但它仅用于关闭窗口。

标签: javascript ajax post model-view-controller


【解决方案1】:

试试这个

<script type="text/javascript">
$(function () {
    $("#dialog-confirm").dialog({
        resizable: false,
        height: 140,
        modal: true,
        buttons: {
            "Ok": function () {
                $.ajax({
                    type: "POST",
                    url: "/ControllerName/ActionName",
                    data: { name: '@ViewBag.ProductName', id: '@ViewBag.ProductID' },
                    success: function () {
                        alert("succes");
                        $("#result").html('submitted successfully');

                    },
                    error: function () {
                        alert("failure");
                        $("#result").html("there is error with submit");
                    }
                })
                $(this).dialog("close");
            },
            Anuluj: function () {
                $(this).dialog("close");
            }
        }
    });
});

【讨论】:

    猜你喜欢
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 2019-12-09
    • 1970-01-01
    • 2019-05-03
    • 2021-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多