Reputation: 89
Why is it that my code on Ajax success is not functioning.
View
$.connection.hub.start().done(function() {
// Populate the object with values
$(document).on("click", "#btn_submit_schedule", function () {
bootbox.confirm({
title: "Save these details?",
message: html,
buttons: {
confirm: {
label: 'YES',
className: 'btn-success'
},
cancel: {
label: 'NO',
className: 'btn-danger'
}
},
callback: function (result) {
if (result === true) {
$.ajax({
type: 'POST',
url: '/Member/CreateTicket',
data: obj,
succes: function (controlResult) {
console.log(controlResult);
if (controlResult === true) {
$.notify({
icon: 'glyphicon glyphicon-star',
message: "Ticket has been saved"
}, {
animate: {
enter: 'animated bounceIn',
exit: 'animated bounceOut'
}
}, {
type: 'success'
});
$("#create_ticket_status").html("Created ticket successfully.");
chat.server.getPendingRequestCount(document.getElementById("selected_id").value);
} else {
$("#create_ticket_status").html(result);
$.notify({
icon: 'glyphicon glyphicon-star',
message: "An error has occured on creating the ticket"
}, {
animate: {
enter: 'animated bounceIn',
exit: 'animated bounceOut'
}
}, {
type: 'success'
});
}
},
error: function() {
$.notify({
icon: 'glyphicon glyphicon-star',
message: "Error has occured in creating ticket."
}, {
animate: {
enter: 'animated bounceIn',
exit: 'animated bounceOut'
}
}, {
type: 'success'
});
}
});
}
}
});
});
});
Controller
[HttpPost]
public ActionResult CreateTicket(CreateTicket ticket)
{
if (ModelState.IsValid)
{
var tm = new TicketManager();
var controlResult = tm.CreateTicket(ticket);
return controlResult ? Json(true) : Json("An error occured on creating the ticket.");
}
return Json("Fill-in the required fields.");
}
I can actually see the result as true in the reponse tab of the inspector and I can save in my database. Why the success function is not working, is beyond me. If I intentionally create an error, I can see the my error function works. Can you point out what I am doing wrong?
Upvotes: 1
Views: 82
Reputation: 1091
There's a typo
succes: function (controlResult) {
can you correct it and try as success with double s
Upvotes: 2