Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the considerations for jQuery.ajax

Shulou Source: shulou.com Published: 2022-06-01 07:34:55 09月26日 Update

This article mainly shows you "what are the matters needing attention in jQuery.ajax", which is easy to understand and clear, hoping to help you solve your doubts. Let the editor lead you to study and learn this article "what are the matters needing attention in jQuery.ajax?"

Due to browser security restrictions, most "Ajax" requirements follow the same origin policy; the request cannot successfully retrieve data from different domains, subdomains, or protocols.

Requests in the form of Script and JSONP are not subject to the same origin policy.

Example:

Example: save the data to the server and display the information when it is successful.

$.ajax ({

Type: "POST"

Url: "some.php"

Data: {name: "John", location: "Boston"}

}) .done (function (msg) {

Alert ("Data Saved:" + msg)

})

Example: loads the latest version of a HTML web page.

$.ajax ({

Url: "test.html"

Cache: false

}) .done (function (html) {

$("# results") .append (html)

})

Example: sends XML data to the server. Set the processData option to false to prevent automatic conversion of data formats.

Var xmlDocument = [create xml document]

Var xmlRequest = $.ajax ({

Url: "page.php"

ProcessData: false

Data: xmlDocument

})

XmlRequest.done (handleResponse)

Example: send id to the server as data, save some data to the server, and know the user once it is completed. If the request fails, remind the user.

Var menuId = $("ul.nav"). First (). Attr ("id")

Var request = $.ajax ({

Url: "script.php"

Type: "POST"

Data: {id: menuId}

DataType: "html"

})

Request.done (function (msg) {

("# log") .html (msg)

})

Request.fail (function (jqXHR, textStatus) {

Alert ("Request failed:" + textStatus)

})

Example: load and execute a JavaScript file.

$.ajax ({

Type: "GET"

Url: "test.js"

DataType: "script"

})

The above is all the contents of this article "what are the points for attention in jQuery.ajax?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Data servers services matters notes content articles success users learning help restrictions differences security examples information forms policies documents easy to understand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Docker Linux OPPO Reno Xiaomi