dan dan - 1 year ago 82
JSON Question

What causes $.ajax to result a full post-back

Could someone tell me what causes a $.ajax 'POST' request to result a full post-back (full page refresh)?

I'm using the $.ajax 'POST' in the ASP.NET MVC context, where the view is calling the controller method (which returns a JSON result) through a $.ajax 'POST' request.

The code is below.

// View.
<button id="save" onclick="saveClick()" />

// View.
<script type="text/javascript">

function saveClick() {
if (!$("form").valid()) {
return false;

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) {

return true;

function getJsonTicket() {


// Controller action.
public virtual JsonResult SaveTicket(Ticket newTicket)
return Json(new CreateTicketViewModel {SaveResult = "success"});
return Json(new CreateTicketViewModel { SaveResult = "error" });

Answer Source


<button id="save" type="button" onclick="saveClick()" />

to make sure form is not posted by this button.


The default value for the type attribute of button elements is "submit".


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download