【问题标题】:Alert does not work on AJAX success [closed]警报不适用于 AJAX 成功[关闭]
【发布时间】:2017-07-29 20:06:05
【问题描述】:

我有将数据写入表的 AJAX 脚本

这里是代码

<script>
$('#save_appointment').click(function () {
    addAppointmentInternal();
});
function addAppointmentInternal() {
    $.ajax({
        type: 'Post',
        dataType: 'Json',
        data: {
            Start: $('#startAppointment').val(),
            End: $('#endAppointment').val(),
            Title: $('#title').val()
        },
        url: '@Url.Action("AddingInternalAppointment","Calendar")',
        sucess: function (da) {
            if (da.Result === "Success") {
                alert();
            } else {
                alert('Error' + da.Message);
            }
        },
        error: function(da) {
            alert('Error');
        }
    });
}

这是后端代码

 public ActionResult AddingInternalAppointment(string Start, string End, string Title)
    {
        Appointment appointment = new Appointment()
        {
            Start_appointment = Start,
            End_appointment = End,
            Title = Title
        };
        db.Appointments.Add(appointment);
        db.SaveChanges();
        return Json(new { Result = "Success", Message = "Saved Successfully" });
    }

一切都好。数据正在写入表。但是我有问题,成功后我没有收到警报消息。

哪里有问题?

【问题讨论】:

  • === 在你的 javascript 中是 == 吗?
  • @Sybren - === 是 JavaScript 中有效的相等运算符。由于 JavaScript 是弱类型,== 是弱类型相等比较,=== 是强类型相等。
  • 试试console.log(da) 确保你做对了,请给我看。

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


【解决方案1】:

success: ajax 成功中的拼写错误。您正在使用成功。检查并更正它。

改变

sucess: function (da) {

success: function (da) {

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-16
    • 2014-08-13
    • 1970-01-01
    • 1970-01-01
    • 2017-05-13
    • 2017-06-16
    • 2011-09-22
    • 2018-05-31
    相关资源
    最近更新 更多