Home > Web Front-end > JS Tutorial > javascript jQuery $.post $.ajax用法_jquery

javascript jQuery $.post $.ajax用法_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 19:02:59
Original
1047 people have browsed it

jQuery.post( url, [data], [callback], [type] ): Use POST method to make asynchronous requests


Parameters:

url (String): Send request URL address.

data (Map): (Optional) The data to be sent to the server, expressed in the form of Key/value pairs.

callback (Function): (Optional) Callback function when loading is successful (this method is called only when the return status of Response is success).

type (String): (optional) The official description is: Type of data to be sent. In fact, it should be the type of client request (JSON, XML, etc.)

This is a simple POST request function to replace the complex $.ajax. The callback function can be called when the request is successful. If you need to execute a function on error, use $.ajax. Sample code:

Ajax.aspx:

Response.ContentType = "application/json";Response.Write("{result: '" Request["Name"] ",Hello! (This message comes from the server)'}");jQuery code:
$.post("Ajax.aspx", { Action: "post", Name: "lulu" }, function (data, textStatus){ // data can be xmlDoc, jsonObj, html, text, etc.                 //this; //                                                                                                                               . "); Click to submit:

Here the request format is set to "json":


$.ajax() This is the underlying AJAX implementation of jQuery. For simple and easy-to-use high-level implementations, see $.get, $.post, etc.

There are several Ajax event parameters here: beforeSend, success, complete, error. We can define these events to handle each of our Ajax requests well.

$.ajax({url: 'stat.php',

type: 'POST',

data:{Name: "keyun"},

dataType: 'html',

timeout: 1000,

error: function(){alert('Error loading PHP document');},

success : function(result){alert(result);}

});

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template