$.ajaxPrefilter() Vs $.ajaxSetup() - jQuery Ajax

后端 未结 2 687
南笙
南笙 2020-12-30 05:18

While learning through ajax in jQuery, I came across 2 terms, viz., $.ajaxPrefilter() and $.ajaxSetup(). All I can find out is that these

2条回答
  •  萌比男神i
    2020-12-30 05:57

    $.ajaxSetup simply takes an options object, and uses it as the defaults for future $.ajax() calls (and other calls that are shortcuts for this, like $.get). For instance,

    $.ajaxSetup( { dataType: 'json' });
    

    makes this the default dataType for future calls.

    $.ajaxPrefilter lets you run a custom function before sending each AJAX request to the server. It can examine the options to that call, and then change them in any way that it wants. So it provides much more flexibility and control than $.ajaxSetup.

提交回复
热议问题