Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

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

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

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

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

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

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

saekis
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした