Graphene News and Technology > graphene > jQuery ajax {post(26041)}27861;

jQuery ajax {post(26041)}27861;

graphene 2021-06-22 16:22 107
Definition and Usage The

post() method loads data from the server through an HTTP post request

grammar,data,success(data, textStatus, jqXHR),dataType)
parameter describe url Required. Specifies which URL to send the request to. data Optional. Map or string value. Specifies the data to be sent to the server with the request. success(data, textStatus, jqXHR) Optional. The callback function to execute when the request succeeds. dataType

is optional. Specifies the data type of the expected server response

performs intelligent judgment (XML, JSON, script or HTML) by default

detailed description

This function is an abbreviated Ajax function, equivalent to:

type: 'POST',
url: url,
data: data,
success: success,
dataType: dataType

according to the different MIME types of the response, the return data passed to the success callback function is also different. These data can be XML root elements, text strings, JavaScript files or JSON objects. You can also pass the text status of the response to the success callback function

for jQuery 1.5, you can also pass the jqxhr object to the success callback function (the XMLHttpRequest object is passed in jQuery 1.4)

Most implementations of

specify a success function:

$.post(" ajax/test.html",  function(data) {
$(". result"). html(data);

This example reads the requested HTML fragment and inserts it into the page

The page read by

post is not cached, so the cache and ifModified options in jQuery. Ajaxsetup () do not affect these requests

Note: due to the limitation of browser security, most Ajax requests follow the same origin policy; The request could not successfully retrieve data from a different domain, subdomain, or protocol

comment: if a request initiated by jQuery. Post() returns an error code, there will be no prompt unless the script has called the global. Ajaxerror() method. Or for jQuery 1.5, the. Error() method of jqxhr object returned by jQuery. Post() can also be used for error handling