Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

1. Definitions and Usage

The Ajax () method loads remote data through HTTP requests.

This method is the lowest level AJAX implementation of jQuery. Easy-to-use high-level implementations see.get,.get,.get,.post, etc. $.ajax() returns the XMLHttpRequest object it created. In most cases you don’t need to manipulate this function directly, unless you need to manipulate unusual options for more flexibility.

In the simplest case, $.ajax() can be used without any arguments.

Note: All options can be set globally with the $.ajaxsetup () function.

2, grammar,

jQuery.ajax([settings])
Copy the code

3. Common parameters

Please stamp more parameters: www.w3school.com.cn/jquery/ajax…

4, the instance,

1) Load a text through AJAX:

JQuery code:

$(document).ready(function(){
  $("#b01").click(function(){
  htmlobj=$.ajax({url:"/jquery/test1.txt",async:false});
  $("#myDiv").html(htmlobj.responseText);
  });
});
Copy the code

HTML code:

<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button id="b01" type="button">Change Content</button>
Copy the code

2) Send a request to the server via AJAX:

$(function(){var dataList= {}; $. Ajax ({// request type: "POST", // request content encoding type: "application/json; Charset = utf-8 ", / / request the address of the server url: "http://127.0.0.1/admin/list/", / / the data, a json string data: Json.stringify (dataList), // Request success callback function success: function(result) {console.log(result); }, // Error: function(e){console.log(e.status); console.log(e.responseText); }}); });Copy the code

Please feel free to discuss in the comments section. The nuggets will draw 100 nuggets in the comments section after the diggnation project. See the event article for details.