SyntaxStudy
Sign Up
Home jQuery Reference $.getJSON() / .load()

$.getJSON() / .load()

method

$.getJSON() fetches JSON data; .load() loads HTML from a URL into a selected element.

Syntax

$.getJSON(url, data, callback) $(target).load(url)

Example

javascript
// Load JSON data
$.getJSON('/api/products', function(products) {
    products.forEach(p => {
        $('#list').append(`<li>${p.name}: $${p.price}</li>`);
    });
});

// Load HTML into element
$('#sidebar').load('/partials/sidebar.html');

// Load specific fragment
$('#news').load('/news.html #latest-articles');