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
Laravel Eloquent ORM — a model class mapping to a database table with query methods
Laravel Eloquent ORM: The Complete Guide to Querying Your Database
June 16, 2026
Set vi as the default editor in Ubuntu — a terminal opening the vim editor
How to Set vi (Vim) as the Default Editor in Ubuntu
June 8, 2026
rsync says ALL DONE but files are missing — a terminal showing ALL DONE next to an empty folder
rsync Says “ALL DONE” but Files Are Missing: How to Verify
June 8, 2026
Migrate a website to a new server with rsync — files copying from an old server to a new one over SSH
How to Migrate a Website to a New Server With rsync
June 8, 2026
Bun runtime — faster JS toolkit replacing npm in Laravel projects
How to Install Bun Runtime on Ubuntu (And Use It in a Laravel Project)
May 24, 2026

You Might Also Like

WooCommerce remove checkout fields — woocommerce_checkout_fields filter unsetting fields
Web Development

How to Remove Checkout Fields in WooCommerce

6 Min Read
Get the selected radio button value with jQuery
Web Development

How to Get the Selected Radio Button Value in jQuery

3 Min Read
Laravel DataTables HTML column — rawColumns opt-out of the default escaping
Web Development

How to Add an HTML Column in Laravel DataTables

7 Min Read
Deleting a Laravel user cascades to remove related posts, photos, and notifications
Web Development

How to Delete Related Records in Laravel Eloquent

6 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?