【问题标题】:Jquery Ajax working in Local Machine not in ServerJquery Ajax 在本地机器上工作而不是在服务器上
【发布时间】:2021-10-12 22:22:55
【问题描述】:

HTML 代码

$('#btnTariefVerwijderen').click(function () {             
        if (TariefId != undefined && TariefId != "" && TariefId != null) {
            if (window.confirm("Weet u zeker dat u de gesselecteerde rij(en) wilt verwijderen uit de database?")) {
                var url = '/Onderhoud/DeleteTarief?TariefId=' + TariefId;
                $.ajax({
                    cache: false,
                    type: "GET",
                    url: url,
                    contentType: "application/json; charset=utf-8",
                    //data: { objectId: objectId, type: type },
                    dataType: "json",
                    success: function (Data) {
                        TariefId = null;
                        DisplayVerordeningTariefGrid();
                    }
                });
            }
        }
        else
            ShowMessage("Please select the tarief to delete");
    });

C#代码

       public ActionResult DeleteTarief(decimal TariefId)
        {
            if (ModelState.IsValid)
            {
                _onderhoudRepository.DeleteTariefItem(TariefId,HttpContext.User.Identity.Name);
                //return RedirectToAction("SelecterenPuttenData", new { objectId = objectId, type = type });
                return Json(new { success = true }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { success = false }, JsonRequestBehavior.AllowGet);
            }
        }

该功能仅在本地计算机中触发,而不在服务器中触发。有人可以帮我从这里出去吗。 Jquery 文件在本地 Visual Studio 中运行良好

【问题讨论】:

  • 您遇到什么错误?你检查你的网络标签了吗?
  • @johnSmith 在 localhost [Visual Studio] 中我没有收到任何错误,但在部署到服务器后我收到以下错误“GET webl.com/Controller/… net::ERR_EMPTY_RESPONSE”这在控制台中
  • TariefId 的奇怪类型小数?你确定不是错字吗?你能举一个 TariefId 的例子吗?

标签: javascript c# jquery ajax asp.net-mvc


【解决方案1】:

你可以试试这个吗?

$('#btnTariefVerwijderen').click(function () {             
    if (TariefId != undefined && TariefId != "" && TariefId != null) {
        if (window.confirm("Weet u zeker dat u de gesselecteerde rij(en) wilt verwijderen uit de database?")) {
            $.ajax({
                cache: false,
                url: '@Url.Action("DeleteTarief", "Onderhoud")',
                type: 'POST',
                dataType: 'json',
                data: {
                    "TariefId":TariefId,
                },
                success: function (Data) {
                    TariefId = null;
                    DisplayVerordeningTariefGrid();
                }
            });
        }
    }
    else
        ShowMessage("Please select the tarief to delete");
});

【讨论】:

  • 在本地主机中工作而不在服务器中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-08-14
  • 2017-09-29
  • 1970-01-01
  • 2015-08-28
  • 2019-05-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多