Coding⏱️ 1 min read📅 2026-05-31

How to Fix: Set timeout for ajax (jQuery)

Set timeout for AJAX request using jQuery to prevent blocking and handle server downtime.

Quick Answer: Use the async option and set a timeout in the error callback function, e.g. $.ajax({ url: 'test.html', async: true, timeout: 3000, error: function() { console.error('Timeout'); } });

Sometimes success function works good, sometimes not. How do I set timeout for this ajax request? In example, 3 seconds, if time is out, then show an error.

🔍 Why This Happens

  • [Cause]

✅ Best Solutions to Fix It

Method 1: Using Async/Await

  1. Step 1: Wrap your ajax request in an async/await function

Method 2: Using Timeout Option

  1. Step 1: Add the timeout option to your ajax request, e.g. $.ajax({ url:

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions