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.

jsfiddle

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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -