Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

jquery
communitycreator

What is the ajax() method in jQuery?

Silvija Prozinger

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

ajax() is a jQuery method that is used to perform an AJAX (asynchronous HTTP) request using jQuery.

The syntax for the ajax() method is as follows:

$.ajax({name:value, name:value, ... })

Parameters

The parameters specify one or more name/value pairs for the AJAX request:

  • async: A boolean value that indicates whether the request is asynchronous. The default value is true.
  • complete(xhr,status): The function to run when the request is finished, after the success and error functions.
  • dataType: The expected data type the server should respond with.
  • error(xhr,status,error): A function to run if the request fails.
  • success(result,status,xhr): A function to run if the request succeeds.
  • type: Specifies what type of request it is (GET or POST).
  • url: Most commonly used in this situation, it specifies the URL to send the request. The default is the current page.

To explore more parameters for the ajax() method, click here.

Example

Below is a code example that demonstrates the use of the ajax() method:

$.ajax({
url: "example.html",
success: function(result){
$("#div1").html(result);
}});

In the code above, a request is sent to the example.html and upon success, the result of that request is passed to a function with the success parameter.

RELATED TAGS

jquery
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring