Table of Contents
Parameters
cache---Boolean type" >cache---Boolean type
complete---Function/Array type" >complete---Function/Array type
contents---Object Type1.5 New" >contents---Object Type1.5 New
contentType---String Type" >contentType---String Type
context---Object type" >context---Object type
converters --- Object Type1.5 New" >converters --- Object Type1.5 New
crossDomain---Boolean Type1.5 New" >crossDomain---Boolean Type1.5 New
data---Any type of data " >data---Any type of data
dataFilter---Function type" >dataFilter---Function type
dataType---String type" >dataType---String type
error---Function/Array type" >error---Function/Array type
global---Boolean type" >global---Boolean type
headers---Object Type1.5 New" >headers---Object Type1.5 New
ifModified---Boolean type" >ifModified---Boolean type
isLocal---Boolean type1.5.1 Newly added" >isLocal---Boolean type1.5.1 Newly added
jsonp---String类型" >jsonp---String类型
jsonpCallback---String/Function类型" >jsonpCallback---String/Function类型
mimeType---String类型1.5.1 新增" >mimeType---String类型1.5.1 新增
password---String类型" >password---String类型
processData---Boolean类型" >processData---Boolean类型
scriptCharset---String类型" >scriptCharset---String类型
statusCode---Object类型1.5 新增" >statusCode---Object类型1.5 新增
success---Function/Array类型" >success---Function/Array类型
timeout---Number类型" >timeout---Number类型
traditional---Boolean类型" >traditional---Boolean类型
type---String类型" >type---String类型
url --- String类型" >url --- String类型
username --- String类型" >username --- String类型
xhr --- Function类型" >xhr --- Function类型
返回值
示例&说明
Home Web Front-end Front-end Q&A what is ajax function

what is ajax function

Dec 17, 2021 am 11:24 AM

The ajax function refers to the jQuery.ajax() function, which is used to load remote data through background HTTP requests. It is an AJAX technology implementation encapsulated by jQuery. Through this function, we can obtain remote data without refreshing the current page. data on the server.

what is ajax function

The operating environment of this article: Windows 7 system, jquery version 3.2.1, Dell G3 computer.

What is the ajax function?

jQuery.ajax() function detailed explanation

jQuery.ajax() function is used to load through background HTTP requests Remote data.

jQuery.ajax() The function is an implementation of AJAX technology encapsulated by jQuery. Through this function, we can obtain data on the remote server without refreshing the current page.

jQuery.ajax() The function is the underlying AJAX implementation of jQuery. jQuery.get(), jQuery.post(), load(), jQuery.getJSON(), jQuery.getScript() and other functions are all simplified forms of this function (they all call this function, but the parameter settings are different or have some differences). omitted).

This function belongs to the global jQuery object (can also be understood as a static function).

Parameters

Please find the corresponding parameters according to the parameter names defined in the previous syntax section.

Parameters Description
url String type URL request string.
settings Optional/Object type An Object object, each attribute of which is used to specify additional parameter settings required to send a request .

Parameterssettings is an object, jQuery.ajax() can identify the following properties of the object (they are all optional):

accepts --- ObjectType

Default value: Depends At dataType attribute.

The content type request header sent is used to tell the server what type of response the browser can receive from the server.

async --- Boolean type

Default value: true.

Indicates whether it is an asynchronous request. Synchronous requests lock the browser until the remote data is obtained and no other operations can be performed.

beforeSend---Function type

Specify what needs to be executed before the request is sent Callback. This function also has two parameters: one is the jqXHR object, and the other is the current settings object. This is an Ajax event. If the function returns false, this ajax request will be cancelled.

cache---Boolean type

Default value: true(When dataType is 'script' or 'jsonp', the default is false).

Indicates whether to cache URL requests. If set to false it will force the browser not to cache the current URL request. This parameter is only valid for HEAD and GET requests (POST requests themselves will not be cached).

complete---Function/Array type

Specified requestComplete The callback function that needs to be executed after (regardless of success or failure). This function also has two parameters: one is the jqXHR object, and the other is a string representing the request status ('success', 'notmodified', 'error', 'timeout', 'abort' or 'parsererror '). This is an Ajax event.

Starting from jQuery 1.5, the attribute value can be multiple functions in the form of array, and each function will be executed by a callback.

contents---Object Type1.5 New

An object paired with "{string:regular expression}" to determine how jQuery will parse the response, given its content type.

contentType---String Type

Default value: 'application/x- www-form-urlencoded; charset=UTF-8'.

Send data to the server using the specified content encoding type. The W3C's XMLHttpRequest specification stipulates that the charset is always UTF-8. If you change it to another character set, you cannot force the browser to change the character encoding.

context---Object type

Used to set Ajax related callback functions Context object (that is, the this pointer within the function).

converters --- Object Type1.5 New

Default value: {'* text': window.String, 'text html': true, 'text json': jQuery.parseJSON, 'text <span id="9_nwp">xml': jQuery.parseXML}</span>.

A data type converter. The value of each converter is a function that returns the converted value of the response.

crossDomain---Boolean Type1.5 New

Default value: Same-domain request is false, cross-domain request is true.

Indicates whether it is a cross-domain request. If you want to force cross-domain requests within the same domain (as in JSONP form), set this to true. This allows server-side redirection to another domain, for example.

data---Any type of data

sent to the server will be automatically forwarded is of string type. If it is a GET request, it will be appended to the URL.

dataFilter---Function type

Specifies the callback for processing the raw data of the response function. This function also has two parameters: one is a string representing the original data of the response, and the other is the <span id="8_nwp">dataType</span> attribute string.

dataType---String type

Default value: jQuery smart guess, guess Scope (xml, json, script or html)

Specifies the data type returned. The attribute value can be:

  • 'xml': Returns an XML document that can be processed using jQuery.
  • 'html': Returns an HTML string.
  • 'script': Returns JavaScript code. Results are not cached automatically. Unless the cache parameter is set. Note: When making remote requests (not under the same domain), all POST requests will be converted into GET requests. (Because the DOM script tag will be used to load)
  • 'json': Returns JSON data. JSON data will be parsed using strict syntax (attribute names must be double quoted, and all strings must be double quoted), and an error will be thrown if parsing fails. Starting with jQuery 1.9, responses with empty content will return null or {}.
  • 'jsonp': JSONP format. When calling a function using JSONP format, such as "url?callback=?", jQuery will automatically replace the second ? with the correct function name to execute the callback function.
  • 'text': Returns a plain text string.

error---Function/Array type

Specify the callback function to be executed when the request fails. This function has 3 parameters: jqXHR object, request status string (null, 'timeout', 'error', 'abort' and 'parsererror'), error message string (text description part of the response status, such as 'Not Found' ' or 'Internal Server Error'). This is an Ajax event. Cross-domain scripts and cross-domain JSONP requests will not call this function.

Starting from jQuery 1.5, the attribute value can be multiple functions in the form of array , each function will be executed by a callback.

global---Boolean type

Default value: true.

Indicates whether to trigger the global Ajax event. Setting this value to false will prevent global event handlers from being triggered, such as ajaxStart() and ajaxStop(). It can be used to control various Ajax events.

headers---Object Type1.5 New

default value:{}.

Specify additional request header information in object form. The request header X-Requested-With: XMLHttpRequest will always be added, but you can also modify the default XMLHttpRequest value here. The value in headers can override the request header set in the beforeSend callback function (meaning beforeSend is called first).

$.ajax({
    url: "my.php" ,
    headers: {        "Referer": "http://www.365mini.com" // 有些浏览器不允许修改该请求头
        ,"User-Agent": "newLine" // 有些浏览器不允许修改该请求头
        ,"X-Power": "newLine"
        ,"Accept-Language": "en-US"
    }
});
Copy after login

ifModified---Boolean type

Default value: false .

Allows the current request to obtain new data only when the server data changes (if it has not changed, the browser obtains the data from the cache). It uses HTTP header information Last-Modified to determine. Starting with jQuery 1.4, it also checks the server-specified 'etag' to determine whether the data has been modified.

isLocal---Boolean type1.5.1 Newly added

Default: Depends on the current location protocol.

允许将当前环境视作"本地",(例如文件系统),即使默认情况下jQuery不会如此识别它。目前,以下协议将被视作本地:file*-extensionwidget

jsonp---String类型

重写JSONP请求的回调函数名称。该值用于替代"url?callback=?"中的"callback"部分。

jsonpCallback---String/Function类型

为JSONP请求指定一个回调函数名。这个值将用来取代jQuery自动生成的随机函数名。

从jQuery 1.5开始,你也可以指定一个函数来返回所需的函数名称。

mimeType---String类型1.5.1 新增

一个mime类型用来覆盖XHR的mime类型。

password---String类型

用于响应HTTP访问认证请求的密码。

processData---Boolean类型

默认值:true

默认情况下,通过<span id="4_nwp">data</span>属性传递进来的数据,如果是一个对象(技术上讲,只要不是字符串),都会处理转化成一个查询字符串,以配合默认内容类型 "application/x-www-form-urlencoded"。如果要发送 DOM树信息或其它不希望转换的信息,请设置为false

scriptCharset---String类型

设置该请求加载的脚本文件的字符集。只有当请求时dataType为"jsonp"或"script",并且type是"GET"才会用于强制修改charset。这相当于设置

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1659
14
PHP Tutorial
1258
29
C# Tutorial
1232
24
React's Role in HTML: Enhancing User Experience React's Role in HTML: Enhancing User Experience Apr 09, 2025 am 12:11 AM

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

React and the Frontend: Building Interactive Experiences React and the Frontend: Building Interactive Experiences Apr 11, 2025 am 12:02 AM

React is the preferred tool for building interactive front-end experiences. 1) React simplifies UI development through componentization and virtual DOM. 2) Components are divided into function components and class components. Function components are simpler and class components provide more life cycle methods. 3) The working principle of React relies on virtual DOM and reconciliation algorithm to improve performance. 4) State management uses useState or this.state, and life cycle methods such as componentDidMount are used for specific logic. 5) Basic usage includes creating components and managing state, and advanced usage involves custom hooks and performance optimization. 6) Common errors include improper status updates and performance issues, debugging skills include using ReactDevTools and Excellent

React Components: Creating Reusable Elements in HTML React Components: Creating Reusable Elements in HTML Apr 08, 2025 pm 05:53 PM

React components can be defined by functions or classes, encapsulating UI logic and accepting input data through props. 1) Define components: Use functions or classes to return React elements. 2) Rendering component: React calls render method or executes function component. 3) Multiplexing components: pass data through props to build a complex UI. The lifecycle approach of components allows logic to be executed at different stages, improving development efficiency and code maintainability.

React's Ecosystem: Libraries, Tools, and Best Practices React's Ecosystem: Libraries, Tools, and Best Practices Apr 18, 2025 am 12:23 AM

The React ecosystem includes state management libraries (such as Redux), routing libraries (such as ReactRouter), UI component libraries (such as Material-UI), testing tools (such as Jest), and building tools (such as Webpack). These tools work together to help developers develop and maintain applications efficiently, improve code quality and development efficiency.

Frontend Development with React: Advantages and Techniques Frontend Development with React: Advantages and Techniques Apr 17, 2025 am 12:25 AM

The advantages of React are its flexibility and efficiency, which are reflected in: 1) Component-based design improves code reusability; 2) Virtual DOM technology optimizes performance, especially when handling large amounts of data updates; 3) The rich ecosystem provides a large number of third-party libraries and tools. By understanding how React works and uses examples, you can master its core concepts and best practices to build an efficient, maintainable user interface.

React: The Power of a JavaScript Library for Web Development React: The Power of a JavaScript Library for Web Development Apr 18, 2025 am 12:25 AM

React is a JavaScript library developed by Meta for building user interfaces, with its core being component development and virtual DOM technology. 1. Component and state management: React manages state through components (functions or classes) and Hooks (such as useState), improving code reusability and maintenance. 2. Virtual DOM and performance optimization: Through virtual DOM, React efficiently updates the real DOM to improve performance. 3. Life cycle and Hooks: Hooks (such as useEffect) allow function components to manage life cycles and perform side-effect operations. 4. Usage example: From basic HelloWorld components to advanced global state management (useContext and

React vs. Backend Frameworks: A Comparison React vs. Backend Frameworks: A Comparison Apr 13, 2025 am 12:06 AM

React is a front-end framework for building user interfaces; a back-end framework is used to build server-side applications. React provides componentized and efficient UI updates, and the backend framework provides a complete backend service solution. When choosing a technology stack, project requirements, team skills, and scalability should be considered.

The Future of React: Trends and Innovations in Web Development The Future of React: Trends and Innovations in Web Development Apr 19, 2025 am 12:22 AM

React's future will focus on the ultimate in component development, performance optimization and deep integration with other technology stacks. 1) React will further simplify the creation and management of components and promote the ultimate in component development. 2) Performance optimization will become the focus, especially in large applications. 3) React will be deeply integrated with technologies such as GraphQL and TypeScript to improve the development experience.

See all articles