Detailed explanation of $.ajax() method parameters in Jquery
This article is my daily compilation of detailed explanations about jquery ajax() parameters. Since there are many parameters in the jquery ajax method, it is a bit difficult to remember them with your brain. Now I will organize and share the content on the website for your reference
As the saying goes, a good memory is not as good as a bad pen. The following is a detailed explanation of the ajax method parameters in jquery. Here are some for your reference.
1.url:
is required to be a String type parameter, (default is the current page address) and the address to which the request is sent.
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 parameter of type Number 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. All requests are asynchronous requests. If you need to send synchronous requests, 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 Boolean type parameters, the default is true (when dataType is script, the default is false), set to false will not load from the browser cache Request information.
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 http package mime information 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 cache parameters are set. Note that when making remote requests (not under the same domain), all post requests will be converted into get requests.
json: Return JSON data.
jsonp: JSONP format. When calling a function using the SONP form, 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){
## Parameter of Function type, callback function called after the request is completed (called when the request succeeds or fails). Parameters: XMLHttpRequest object and a string describing the successful request type.
Function (xmlhttpRequest, TextStatus) {
this; // Call the options parameter passed during the AJAX request
## 10.Success: The request is a parameter of the Function type, and the request is successful. The callback function called later has two parameters.
(1) Data returned by the server and processed according to the dataType parameter.
(2) Describe the string of the state.
Function (Data, TextStatus) {
// Data may be XMLDOC, JSONOBJ, HTML, Text, etc.
Requires parameters of Function type, the function to be called when the request fails. This function has three parameters, namely XMLHttpRequest object, error message, and captured error object (optional). The ajax event function is as follows:
function(XMLHttpRequest, textStatus, errorThrown){
Normally only one of textStatus and errorThrown contains information
this; //The options parameters passed when calling this ajax request
}
12.contentType:
is required to be a String type parameter. When sending information to the server, the content encoding type defaults to "application/x-www-form-urlencoded" . This default value is suitable for most applications.
13.dataFilter:
Requires parameters of Function type, a function that preprocesses the original data returned by Ajax. Provide two parameters: data and type. data is the original data returned by Ajax, and type is the dataType parameter provided when calling jQuery.ajax. The value returned by the function will be further processed by jQuery.
Function (data, type) {
// Back to the processing data
Return data;
}
## See Parameters, a function for preprocessing the original data returned by Ajax. Provide two parameters: data and type. data is the original data returned by Ajax, and type is the dataType parameter provided when calling jQuery.ajax. The value returned by the function will be further processed by jQuery.
FUNCTION (data, type) { // Back to the processing data
Return data;
}
## 15.global:
## See parameter, defaults to true. Indicates whether to trigger the global ajax event. Setting to false will not trigger global ajax events, ajaxStart or ajaxStop can be used to control various ajax events.
16.ifModified:
Requires parameters of Boolean type, defaults to false. Only get new data when server data changes. The basis for determining server data changes is the Last-Modified header information. The default value is false, which means header information is ignored.
17.jsonp:
Requires parameters of String type to rewrite the name of the callback function in a jsonp request. This value is used to replace the "callback" part of the URL parameter in a GET or POST request such as "callback=?". For example, {jsonp:'onJsonPLoad'} will cause "onJsonPLoad=?" to be passed to the server.
18.username:
is required to be a String type parameter, used to respond to the username of the HTTP access authentication request.
19.password:
is required to be a String type parameter, which is the password used to respond to the HTTP access authentication request.
20.processData:
Requires a Boolean type parameter, the default is true. By default, the data sent will be converted to an object (technically not a string) to match the default content type "application/x-www-form-urlencoded". If you want to send DOM tree information or other information that you do not want to convert, set it to false.
21.scriptCharset:
is required to be a String type parameter. It will be used to force the character set to be modified only when the dataType is "jsonp" or "script" during the request, and the type is GET. (charset). Usually used when the local and remote content encodings are different.
Case code:
$(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);
}
});
});
});
$.ajax verification login:
<script type="text/javascript" language="javascript">
function IbtnEnter_onclick() {
checklogin();
return false;
}
function checklogin() {
if ($("#TxtUserName").val() == "") {
alert("用户名不能为空!");
$("#TxtUserName").focus();
return false;
}
if ($("#TxtPassword").val() == "") {
alert("密码不能为空!");
$("#TxtPassword").focus();
return false;
}
$.ajax({
type: "POST",
url: "ajax/Handler.ashx?M=" + Math.random(),
data: "username=" + $("#TxtUserName").val().toString() + "&pwd=" + $("#TxtPassword").val().toString(),
success: function (data) {
if (data == "1") {
location.href = "index.aspx";
return true;
}
else {
alert("请确认您输入的用户名或密码输入是否正确!");
$("#TxtUserName").val("");
$("#TxtPassword").val("");
$("#TxtUserName").focus();
return false;
}
}
})
}
</script>
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Web.SessionState;//继承接口IReadOnlySessionState需要引入的命名空间
public class Handler : IHttpHandler, IRequiresSessionState
{
SqlHelper helper = new SqlHelper();
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string username = context.Request.Params["username"].ToString().Trim();
string pwd = context.Request.Params["pwd"].ToString().Trim();
if (username != "" && pwd != "")
{
string sql = @"SELECT * FROM [USER] WHERE USERNAME='"+username+"' AND PASSWORD='"+pwd+"' ";
if (!helper.Exists(sql))
{
context.Response.Write("0");
}
else
{
SqlDataReader reader = helper.ExecuteReader(sql);
while (reader.Read())
{
context.Response.Write("1");
context.Session["username"] = username.ToString().Trim();
context.Session["pwd"] = pwd.ToString().Trim();
}
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future. helpful.
Related articles:
Solution to prevent repeated sending of Ajax requestsAnalysis of the order of data returned by ajax requests
SSH online mall uses ajax to complete asynchronous verification of user names
The above is the detailed content of Detailed explanation of $.ajax() method parameters in Jquery. For more information, please follow other related articles on the PHP Chinese website!
Python vs. JavaScript: Community, Libraries, and ResourcesApr 15, 2025 am 12:16 AMPython and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.
From C/C to JavaScript: How It All WorksApr 14, 2025 am 12:05 AMThe shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.
JavaScript Engines: Comparing ImplementationsApr 13, 2025 am 12:05 AMDifferent JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.
Beyond the Browser: JavaScript in the Real WorldApr 12, 2025 am 12:06 AMJavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.
Building a Multi-Tenant SaaS Application with Next.js (Backend Integration)Apr 11, 2025 am 08:23 AMI built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing
How to Build a Multi-Tenant SaaS Application with Next.js (Frontend Integration)Apr 11, 2025 am 08:22 AMThis article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base
JavaScript: Exploring the Versatility of a Web LanguageApr 11, 2025 am 12:01 AMJavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.
The Evolution of JavaScript: Current Trends and Future ProspectsApr 10, 2025 am 09:33 AMThe latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version






