如何修复这个js脚本发送一个值的方法post

How to fix this js script to send a value by method post

本文关键字:一个 方法 post 何修复 js 脚本      更新时间:2023-09-26

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

我需要在这个提交中添加两个值:
id and name .

我也不知道它应该是什么url,因为方法没有改变。我现在在delete中,但是在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>

试试这个

<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");
            }
        }
    });
});