2017-07-29 43 views
-1

工作,我必须将数据写入表AJAX脚本警报不会对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" }); 
    } 

而且都可以。数据正在写入表格。但我有问题,成功后我没有收到警报信息。

哪里有问题?

+0

''==='是'==在你的JavaScript? – Sybren

+0

@Sybren - '==='是JavaScript中的一个有效的相等运算符。由于JavaScript是弱类型,所以'=='是弱类型的等式比较,'==='是强类型的等式。 –

+0

尝试'console.log(da)'确保你有正确的东西,并且让我看到它。 – Natsathorn

回答

5

success: ajax成功错字错误。你正在使用成功。检查并纠正它。

变化

sucess: function (da) { 

success: function (da) {