


Comprehensive analysis of $.Ajax() method parameters (graphic tutorial)
AJAX is a technology used to create fast dynamic web pages. This article mainly introduces relevant information on comprehensive analysis of $.Ajax() method parameters (recommended). Friends who need it can refer to it
Let me first introduce you to the concept of Ajax
AJAX stands for "Asynchronous Javascript And XML" (asynchronous JavaScript and XML), which refers to a web page that creates interactive web applications. Development Technology.
AJAX = Asynchronous JavaScript and XML (a subset of Standard Universal Markup Language).
AJAX is a technology for creating fast, dynamic web pages.
By exchanging a small amount of data with the server in the background, AJAX can enable asynchronous updates of web pages. This means that parts of a web page can be updated without reloading the entire page.
Traditional web pages (not using AJAX) must reload the entire web page if the content needs to be updated.
ajax method
$.ajax() method is the lowest level Ajax implementation of jQuery. Its structure is:
$.ajax(options)
This method has only one parameter, but this object contains the request settings and callback functions required by the $.ajax() method. Information and parameters exist in the form of key/value, and all parameters are optional. Commonly used parameters are shown in the table below:
1.url
is required to be a String type parameter, (default is the current address) to send the requested page .
2.type
requires parameters of String type, and the request method (post or get) defaults to get. Note that other http request methods such as put and delete can also be used, but are only supported by some browsers.
3.timeout
Requires a Number type parameter and sets the request timeout (milliseconds). This setting will override the global setting of the $.ajaxSetup() method.
4.async
Requires Boolean type parameters, the default setting is true, and all requests are asynchronous requests. If synchronous requests are required, set this option to false. Note that a synchronous request will lock the browser, and the user must wait for the request to complete before other operations can be performed.
5.cache
Requires parameters of Boolean type, the default is true (when dataType is Script, the default is false), set false will not load the request information from the browser cache.
6.data
Requires parameters of type Object or String, data sent to the server. If it is not a string, it will be automatically converted to string format. The get request will be appended to the URL. To prevent this automatic conversion, check the processData option. The object must be in key/value format, for example {foo1:"bar1",foo2:"bar2"} is converted to &foo1=bar1&foo2=bar2. If it is an array, JQuery will automatically assign the same name to different values. For example, {foo:["bar1","bar2"]} is converted to &foo=bar1&foo=bar2.
7.dataType
Requires parameters of String type, expected data type returned by the server. If not specified, jQuery will automatically return responseXML or responseText based on the mine information of the HTTP package and pass it as a callback function parameter. The available types are as follows:
XML: Returns an XML document that can be processed with jQuery.
HTML: Returns plain text HTML information; the included script tag will be executed when inserted into the DOM.
Script: Returns plain text javascript code. Results are not automatically cached unless the cache parameter is set. Note that when making remote requests (not under the same domain), all post requests will be converted into get requests.
json: Returns JSON data.
jsonp: JSON format. When calling a function using JSONP format, such as myurl?callback=?, JQuery will automatically replace the last "?" with the correct function name to execute the callback function.
Text: Returns a plain text string.
8.beforeSend
requires parameters of Function type. You can modify the function of the XMLHttpRequest object before sending the request, such as adding a custom HTTP header. . If false is returned in beforeSend, this ajax request can be canceled. The XMLHttpRequest object is the only parameter.
function(XMLHttpRequest){ this;//调用本次ajax请求时传递的options参数 }
##9.complete
requires parameters of Function type, after the request is completed The callback function called (called if the request succeeds or fails). Parameters: XMLHttpRequest object and a string describing the successful request type.function(XMLHttpRequest,textStatus){ this; //调用本次ajax请求时传递的options参数 }
##10.successRequires parameters of Function type, after the request is successful The callback function called has two parameters.
(1) Data returned by the server and processed according to the dataType parameter.
(2) A string describing the status.
function(data,textStatus){ //data可能是xmlDoc、jsonObj、html、text等 this; //调用本次ajax请求时传递的options参数 }
11.error 要求为Function类型的参数,请求失败时被调用的函数。该函数有3个参数,即XMLHttpRequest对象、错误信息、捕获的错误对象(可选)。ajax事件函数如下: 12.contentType 要求为String类型的参数,当发送信息至服务器时。内容编码类型默认为"application/x-www-form-urlencoded"。该默认值适合大多数应用场合。 13.dataFilter 要求为Function类型的参数,给Ajax返回的原始数据进行预处理的函数。提供data和type两个参数。data是Ajax返回的原始数据,type是调用jQuery.ajax时提供的dataTYpe参数。函数返回的值将由jQuery进一步处理。 14.global 要求为Boolean类型的参数,默认为true。表示是否触发全局ajax事件。设置为false将不会触发全局ajax事件,ajaxStart和ajaxStop可用于控制各种ajax事件。 15.ifModified 要求为Boolean类型的参数,默认为false。仅在服务器数据改变时获取新数据。服务器数据改变判断的依据是Last-Modified头信息。默认值是false,即忽略头信息。 16.jsonp 要求为String类型的参数,在一个jsonp请求中重写回调函数的名字。该值用来替代在"callback=?"这种GET或POST请求中URL参数里的"callback"部分,例如{jsonp:'onJsonPLoad'}会导致将"onJsonPLoad=?"传给服务器。 17.username 要求为String类型的参数,用于响应HTTP访问认证请求的用户。 18.password 要求为String类型的参数,用于响应HTTP访问认证请求的密码。 19.processData 要求为Boolean类型的参数,默认为true。默认情况下,发送的数据将被转换为对象(从技术角度来讲而非字符串)以配合默认内容类型"application/x-www-form-urlencoded"。如果要发送DOM树信息或者其他不希望转换的信息,请设置为false。 20.scriptCharset 要求为String类型的参数,只有当请求时dataType为"jsonp"或者"script",并且type是GET时才会用于强制修改字符集(charset)。通常在本地和远程的内容编码不同时使用。 案例代码: 知识链接: 1、$.each()函数:$.each()函数不同于jQuery对象的each()方法,它是一个全局函数,不操作jQuery对象。该函数接收两个参数,第1个参数是一个数组或对象,第2个参数是一个回调函数。回调函数拥有两个参数:第1个参数为数组的索引或对象的成员,第2个参数为对应的变量或内容。 2、ajaxStart()与ajaxStop():当Ajax请求开始时,会触发ajaxStart()方法的回调函数。当Ajax请求结束时,会触发ajaxStop()方法的回调函数。这些方法都是全局的方法,因此无论创建它们的代码位于何处,只要有Ajax请求发生时,就会触发它们。 有时候页面需要加载一些图片,可能速度回比较慢,如果在加载过程中,不给用户提供一些提示和反馈信息,很容易让用户误认为按钮单击无用,使用户对网站失去信息。 此时,我们就需要为网页添加一个提示信息,常用的提示信息是“加载中...”,代码如下: 当Ajax请求开始时,将此元素显示,用来提示用户Ajax请求正在进行;当Ajax请求结束后,将此元素隐藏。代码如下: 好了,下面再给大家分享一个案例代码: 上面是我整理给大家的,希望今后会对大家有帮助。 相关文章: The above is the detailed content of Comprehensive analysis of $.Ajax() method parameters (graphic tutorial). For more information, please follow other related articles on the PHP Chinese website! function(XMLHttpRequest,textStatus,errorThrown){
//通常情况下textStatus和errorThrown只有其中一个包含信息
this; //调用本次ajax请求时传递的options参数
}
function(data,type){
//返回处理后的数据
return data;
}
$(function(){
$('#send').click(function(){
$.ajax({
type: "GET",
url: "test.json",
data: {username:$("#username").val(), content:$("#content").val()},
dataType: "json",
success: function(data){
$('#resText').empty(); //清空resText里面的所有内容
var html = '';
$.each(data, function(commentIndex, comment){
html += '<p class="comment"><h6>' + comment['username']
+ ':</h6><p class="para"' + comment['content']
+ '</p></p>';
});
$('#resText').html(html);
}
});
});
});
$.each(data,function(commentIndex,comment){
//doSomething;
})
<p id="loading">加载中...</p>
$("#loading").ajaxStart(function(){
$(this).show();
}).ajaxStop(function(){
$(this).hide();
})
$(function(){
$('#send').click(function(){
$.ajax({
type: "GET",
url: "test.json",
data: {username:$("#username").val(), content:$("#content").val()},
dataType: "json",
success: function(data){
$('#resText').empty(); //清空resText里面的所有内容
var html = '';
$.each(data, function(commentIndex, comment){
html += '<p class="comment"><h6>' + comment['username']
+ ':</h6><p class="para"' + comment['content']
+ '</p></p>';
});
$('#resText').html(html);
}
});
});
});

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Tomato Novel is a very popular novel reading software. We often have new novels and comics to read in Tomato Novel. Every novel and comic is very interesting. Many friends also want to write novels. Earn pocket money and edit the content of the novel you want to write into text. So how do we write the novel in it? My friends don’t know, so let’s go to this site together. Let’s take some time to look at an introduction to how to write a novel. Share the Tomato novel tutorial on how to write a novel. 1. First open the Tomato free novel app on your mobile phone and click on Personal Center - Writer Center. 2. Jump to the Tomato Writer Assistant page - click on Create a new book at the end of the novel.

Colorful motherboards enjoy high popularity and market share in the Chinese domestic market, but some users of Colorful motherboards still don’t know how to enter the bios for settings? In response to this situation, the editor has specially brought you two methods to enter the colorful motherboard bios. Come and try it! Method 1: Use the U disk startup shortcut key to directly enter the U disk installation system. The shortcut key for the Colorful motherboard to start the U disk with one click is ESC or F11. First, use Black Shark Installation Master to create a Black Shark U disk boot disk, and then turn on the computer. When you see the startup screen, continuously press the ESC or F11 key on the keyboard to enter a window for sequential selection of startup items. Move the cursor to the place where "USB" is displayed, and then

Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

A summary of how to obtain Win11 administrator rights. In the Windows 11 operating system, administrator rights are one of the very important permissions that allow users to perform various operations on the system. Sometimes, we may need to obtain administrator rights to complete some operations, such as installing software, modifying system settings, etc. The following summarizes some methods for obtaining Win11 administrator rights, I hope it can help you. 1. Use shortcut keys. In Windows 11 system, you can quickly open the command prompt through shortcut keys.

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

Detailed explanation of Oracle version query method Oracle is one of the most popular relational database management systems in the world. It provides rich functions and powerful performance and is widely used in enterprises. In the process of database management and development, it is very important to understand the version of the Oracle database. This article will introduce in detail how to query the version information of the Oracle database and give specific code examples. Query the database version of the SQL statement in the Oracle database by executing a simple SQL statement

In today's society, mobile phones have become an indispensable part of our lives. As an important tool for our daily communication, work, and life, WeChat is often used. However, it may be necessary to separate two WeChat accounts when handling different transactions, which requires the mobile phone to support logging in to two WeChat accounts at the same time. As a well-known domestic brand, Huawei mobile phones are used by many people. So what is the method to open two WeChat accounts on Huawei mobile phones? Let’s reveal the secret of this method. First of all, you need to use two WeChat accounts at the same time on your Huawei mobile phone. The easiest way is to
