Can someone tell me what causes the request $. ajax 'POST' to get full post-back (full page refresh)?
I use $ .ajax 'POST' in an ASP.NET MVC context where the view calls the controller method (which returns the JSON result) via $ .ajax 'POST'.
The code is below.
// View. <button id="save" onclick="saveClick()" />
// View. <script type="text/javascript"> function saveClick() { if (!$("form").valid()) { return false; } $.ajax({ url: '@Url.Action(@MVC.Ticket.ActionNames.SaveTicket, @MVC.Ticket.Name)' type: 'POST', data: JSON.stringify(getJsonTicket()), dataType: 'json', contentType: "application/json", cache: false, success: function(data) { alert(data.SaveResult); } }); return true; } function getJsonTicket() { ... } </script>
// Controller action. public virtual JsonResult SaveTicket(Ticket newTicket) { try { TicketManager.SaveTicket(newTicket); return Json(new CreateTicketViewModel {SaveResult = "success"}); } catch { return Json(new CreateTicketViewModel { SaveResult = "error" }); } }
source share