How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Reload DataTables with a New Ajax URL
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How to Reload DataTables with a New Ajax URL
Web Development

How to Reload DataTables with a New Ajax URL

how7o
By how7o
Last updated: May 22, 2026
4 Min Read
Reload DataTables with a new Ajax URL
SHARE

To reload a DataTable with a new Ajax URL without reinitializing it, grab the existing API object, call ajax.url() with the new endpoint, and then ajax.reload() (or chain .load()). The table stays intact — column definitions, sort state, search box — only the underlying data refreshes.

Contents
  • The three-line update
  • One-line shorthand with .load()
  • Keep the user on the current page
  • Callback after reload
  • When you want filters, not a new URL
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-05-17 with DataTables 2.0. Originally published 2024-03-30, rewritten and updated 2026-05-17.

The three-line update

const history = $('#purchase_history').DataTable();
history.ajax.url('/purchase-history-new');
history.ajax.reload();

$('#table').DataTable() without options returns the existing API object for an already-initialised table. ajax.url() sets the new endpoint; ajax.reload() fires the request.

DataTables reload with new URL — ajax.url() + reload, .load() shorthand, preserve page

One-line shorthand with .load()

$('#purchase_history').DataTable().ajax.url('/purchase-history-new').load();

.load() is equivalent to .reload() after a URL change but reads more like English. It resets pagination to page 1 — usually what you want when the data source changes.

Keep the user on the current page

const history = $('#purchase_history').DataTable();
history.ajax.url('/purchase-history-new');
history.ajax.reload(null, false);   // false = stay on current page

The second argument to ajax.reload() is resetPaging. Pass false to keep the user where they are — useful when changing filters or re-fetching after an edit and you don’t want to jump back to page 1.

Callback after reload

history.ajax.reload((json) => {
    console.log(`Loaded ${json.data.length} rows`);
});

The first argument to ajax.reload() is a callback that receives the server’s JSON response. Use it to update counters, dispatch events, or trigger follow-on actions tied to the fresh data.

When you want filters, not a new URL

const table = $('#purchase_history').DataTable({
    ajax: {
        url:  '/purchase-history',
        data: (d) => {
            d.start_date = $('#start').val();
            d.end_date   = $('#end').val();
            return d;
        },
    },
    // columns: [...]
});

// When filters change
table.ajax.reload();

If the only thing changing is filter parameters (same endpoint, different query string), make ajax.data a function. DataTables calls it on every request, picks up the current filter values, and sends them as part of the request — no URL juggling required.

Frequently asked questions

Why do I need ajax.url() first instead of just ajax.reload()?

ajax.reload() re-fetches from the current Ajax URL. To point at a different endpoint, you have to change the URL first with ajax.url('new-endpoint') — that returns the API object, so you can chain .load() or call ajax.reload() next. Without changing the URL, you get fresh data from the same endpoint.

What’s the difference between .load() and ajax.reload() after changing the URL?

ajax.url('...').load() issues the request immediately and resets pagination to page 1. ajax.url('...'); ajax.reload(null, false) is the version that preserves the current page. The false as the second arg keeps the user on the page they were on (handy if they were deep into pagination and you just changed filters).

How do I get the existing DataTable instance without recreating it?

$('#table').DataTable() (capital D, no options) returns the existing API object for an initialised table. $('#table').dataTable() (lowercase) returns the old jQuery-plugin-style object and is mostly deprecated. Always use the capital-D form for the new API.

Can I pass per-request data, like a filter, without changing the URL?

Yes — make ajax.data a function: ajax: { url: '...', data: (d) => { d.filter = getCurrentFilter(); return d; } }. Each ajax.reload() calls the function fresh and sends the current filter value. No URL gymnastics needed.

Related guides

  • How to Load Data in DataTables Using Ajax
  • How to Create Ajax-Based Pagination in DataTables
  • How to Trigger a Function When DataTables Loads Data

References

DataTables ajax.url(): datatables.net/reference/api/ajax.url(). DataTables ajax.reload(): datatables.net/reference/api/ajax.reload(). DataTables ajax.data: datatables.net/reference/option/ajax.data.

TAGGED:ajaxdatatablesjQuery

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Run JS code on URL hash change with the hashchange event How to Run Code on URL Hash Change in JavaScript
Next Article Remove all non-numeric characters from a PHP string How to Remove All Non-Numeric Characters from a String in PHP
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Run Laravel queue workers with Supervisor
How to Run Laravel Queue Workers in Production with Supervisor
May 23, 2026
Nginx as a reverse proxy for a Node.js app on Ubuntu
How to Set Up Nginx as a Reverse Proxy for Node.js on Ubuntu
May 23, 2026
Install and configure Redis on Ubuntu for Laravel and WordPress
How to Install and Configure Redis on Ubuntu (for Laravel & WordPress)
May 23, 2026
Harden a fresh Ubuntu VPS with UFW, Fail2Ban, and SSH key auth
How to Harden a Fresh Ubuntu VPS: UFW + Fail2Ban + SSH Key Auth
May 23, 2026
Set up Let's Encrypt SSL with Certbot on Ubuntu
How to Set Up Let’s Encrypt SSL with Certbot on Ubuntu (Apache & Nginx)
May 23, 2026

You Might Also Like

Laravel validator exists rule checking a post_id against the posts table
Web Development

How to Use the Laravel Validator Exists Rule

6 Min Read
Duplicate a div into another div with jQuery clone
Web Development

How to Duplicate a DIV into Another DIV with jQuery

4 Min Read
Store a PHP array in a MySQL database with JSON
Web Development

How to Store a PHP Array in a MySQL Database

5 Min Read
WooCommerce dynamic currency switcher — cookie-stored currency applied via woocommerce_currency filter
Web Development

How to Dynamically Change Currency in WooCommerce

7 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?