6
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ajaxSetup()でajax処理共通のデフォルトオプションを設定する

Last updated at Posted at 2016-03-07

恥ずかしながらこのやり方を最近知った。

$.ajaxSetup({
  cache: false,
  timeout: 10000, // 10sec
});

みないな感じで書くと、ajax処理に共通のオプションを設定できる。
タイムアウト秒数とかはある程度統一させたりするだろうから、結構便利。

個々の処理でオプションを設定した場合は、そっちが優先される。

$.ajax({
  url: '/hoge',
  type: 'GET',
  timeout: 600000, // こっちが優先される
}),
....

ちなみに、$.get()メソッドでもajaxSetup()で設定したオプションは適用される。

6
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?