Can you defer ajax setup in jquery 1.5? -


i have this

 $.ajaxsetup({         cache: false     }); 

i wonder can ajaxsetup can $.ajax

var jqxhr = $.ajax({ url: "example.php" })     .success(function() { alert("success"); })     .error(function() { alert("error"); })     .complete(function() { alert("complete"); }); 

so do

 var =    $.ajaxsetup({             cache: false         }) 

then

a.success(function() { alert("success"); }) 

i have not had chance try out yet. once have few minutes going try if knows too. don't see in documentation.

afaik, no won't able - .ajaxsetup() isn't defered object, unlike .ajax() as of jquery v1.5. error saying object doesn't have methods.

if trying setup things happen every .ajax() call (.ajaxsetup() sets defaults .ajax() calls). can access global ajax callbacks like:

  • $.ajaxcomplete(function(){alert("complete");})
  • $.ajaxerror(function(){alert("error");})
  • $.ajaxsuccess(function(){alert("success");})

    if want perform actions on all ajax calls if aiming for? have access callback parameters:

    .ajaxerror(event, xmlhttprequest, ajaxoptions, thrownerror)


    updates follow comments:

    as per docs .ajaxsetup():

    note: global callback functions should set respective global ajax event handler methods: .ajaxstart(), .ajaxstop(), .ajaxcomplete(), .ajaxerror(), .ajaxsuccess(), .ajaxsend() rather within options object $.ajaxsetup()

    so looks there no global handler statuscode callback added in 1.5. again per docs:

    if request successful, status code functions take same parameters success callback; if results in error, take same parameters error callback.

    so think, use example:

    $('body').ajaxsuccess(function(e, xhr, settings) {     if (xhr.status == "200")         alert("your call to: '"+settings.url+"' success (status code: "+xhr.status+")"); });  $('body').ajaxerror(function(e, xhr, settings) {     if (xhr.status == "401")         alert("you not logged remote page!");     if (xhr.status == "404")         alert("the remote page not found: '"+settings.url+"'(status code: "+xhr.status+")"); }); 

    take @ demo here shows successful , un-successful .ajax() call - showing local , global actions, including dealing different statuscodes.


  • Comments

    Popular posts from this blog

    c# - How to set Z index when using WPF DrawingContext? -

    razor - Is this a bug in WebMatrix PageData? -

    visual c++ - Using relative values in array sorting ( asm ) -