jQuery AJAX Shorthand Methods

jQuery AJAX Shorthand Methods

In ajax, get and post are two common submission methods. Formats json is often used.
So jQuery encapsulates them further to make them easier to use.

jQuery AJAX Shorthand Methods List

jQuery.get()Load data from the server using a HTTP GET request.
jQuery.getJSON()Load JSON-encoded data from the server using a GET HTTP request.
jQuery.getScript()Load a javascript file from the server using a GET HTTP request, then execute it.
jQuery.post()Load data from the server using a HTTP POST request.
.load()Load data from the server and place the returned HTML into the matched element.



// use HTTP GET mehtod to request test.php, ingore the data from the server
// request test.php with two parameters
$.get("test.php", { name: "John", time: "2pm" } );
// use a callback function to process the returned data
$.get("test.php", function(data){
  alert("Data Loaded: " + data);


// Load JSON data via HTTP GET request and show it
$.getJSON("test.php", function(json){
  alert("JSON Data: " + json.users[3].name);


// Load and execute test. js, and display information after success.

$.getScript("test.js", function(){
  alert("Script loaded and executed.");


just like jQuery.get(),but use HTTP POST request

$.post("test.php", { name: "John", time: "2pm" } );
$.post("test.php", function(data){
  alert("Data Loaded: " + data);

// Parse the  data from server using json format 
$.post("test.php", { "func": "getNameAndTime" },
     alert(data.name); // John
     console.log(data.time); //  2pm
}, "json");


Load the contents of the feeds.html.
date2019-04-03 00:47:53 From:www.jquerypluginhub.com Author:JPH
Related Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *