javascript - Call ajax.fail() from ajax.success() -
so want conditionally phone call .fail
method within .success
method, how?
var ajaxcall = $.ajax({ url: purl, type: "post", data: pdata, datatype: "json", processdata: false, contenttype: "application/json; charset=utf-8" }) .always(function () { alert("always"); }) .success(function (data) { if (data == "fail") { ajaxcall.fail(); return; } alert("success"); }) .fail(function () { alert("fail"); });
$.ajax
homecoming promise can't directly. best shot :
var fail = function () { alert("fail"); }; var ajaxcall = $.ajax({ url: purl, type: "post", data: pdata, datatype: "json", processdata: false, contenttype: "application/json; charset=utf-8" }) .always(function () { alert("always"); }) .success(function (data) { if (data == "fail") { fail(); return; } alert("success"); }) .fail(fail);
javascript jquery ajax json
No comments:
Post a Comment