Get the App
SLTechnology News&Howtos  ›  Development  › 

How does jquery send post requests

Shulou Source: shulou.com Published: 2022-06-01 01:27:34 09月18日 Update

This article focuses on "how jquery sends post requests". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how jquery sends post requests".

In jquery, you can send a post request using the "$.post ()" method, which is used to load data from the server using the HTTP POST request with the syntax of "$(selector) .post (URL,data, which specifies the function and data type to run when the request succeeds)".

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How does jquery send post requests

The $.post () method uses a HTTP POST request to load data from the server.

The syntax is:

$(selector) .post (URL,data,function (data,status,xhr), dataType)

URL is required. Specifies which URL to send the request to.

Data is optional. Specifies the data to be sent to the server with the request.

Function (data,status,xhr) is optional. Specifies the function to run when the request is successful. Additional parameters:

Data-contains the result data from the request

Status-contains the status of the request ("success", "notmodified", "error", "timeout", "parsererror")

Xhr-contains XMLHttpRequest objects

DataType is optional. Specifies the data type of the expected server response. By default, jQuery determines intelligently. Possible types:

"xml"-an XML document

"html"-HTML as plain text

"text"-plain text string

"script"-runs the response in JavaScript and returns in plain text

"json"-runs the response as JSON and returns as a JavaScript object

"jsonp"-load a JSON block using JSONP and will add a "? callback=?" Go to URL to specify callback.

Examples are as follows:

(document) .ready (function () {$("input") .keyup (function () {txt=$ ("input"). Val (); $.post ("demo_ajax_gethint.php", {suggest:txt}, function (result) {$("span") .html (result);})

Enter a name in the following input box:

First name:

Match:

The PHP code (demo_ajax_gethint) of the instance

Output result:

At this point, I believe you have a deeper understanding of "how jquery sends post requests". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Data method server service run text type success content function object result grammar learning input utility deeper code function interest Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple Shulou Tech Info Docker Shulou Information