Difference between $.ajax(); and $.ajaxSetup();

后端 未结 5 1444
温柔的废话
温柔的废话 2020-12-01 04:18

What is the difference between $.ajax(); and $.ajaxSetup(); in jQuery as in:

$.ajax({
    cache:false
});

and

5条回答
  •  醉梦人生
    2020-12-01 04:59

    To avoid caching, one option is to give different URL for the same resource or data. To generate different URL, you can add a random query string to the end of the URL. This technique works for JQuery, Angular or other type ajax requests.

    myURL = myURL +"?random="+new Date().getTime();
    

    JQuery uses the similar technique via $.ajax({cache:false}); and $.ajaxSetup({cache:false});

    $.ajax({cache:false}) applies the technique on which it is included, $.ajaxSetup({cache:false}); applies the technique for all AJAX functions.

提交回复
热议问题