javascript - How does jquery return functions like success and error -
i've looked though jquery code, , it's not clear me. how make own function return success or error in following code:
$.ajax({ type: "get", url: "/some.xml", success: function() { /** found! **/}, error: function(xhr, status, error) { if(xhr.status==404) { /** not found! **/} } });
$.ajax
passes in object has success
, error
properties on functions. in function call either success
or error
depending on result. example might understand better.
function iftrue(bool, params) { if (bool) params.success(); else params.error(); } iftrue(true, { success: function () { alert('success'); }, error: function () { alert('error'); } }); iftrue(false, { success: function () { alert('success'); }, error: function () { alert('error'); } });
Comments
Post a Comment