var $info = $("#info"); $.ajax({ // Change URL to see error happen url: "/echo/json/", data: { json: JSON.stringify({ "name": "someValue" }) }, type: "POST" }) .then(function (response) { // success $info.text(response.name); }, function () { // failure $info.text("bad things happen to good developers"); }) .always(function () { $info.append("...finally"); });
<div id="info"></div>