JQuery offers load,$.get,$.post three ways to make Ajax easier to write, and it's a complex task that is no longer complicated.
The Load method is the simplest and most commonly used Ajax method in jquery to load remote HTML code into the DOM, which is structured
Load (Url[,data][,callback])
URL of the URL request for the HTML page
Data sent to the server by Key/value
Callback callback function when the request is complete, whether the request succeeds or fails
Example: Loading a test.html file
$ (' #stats '). Load (' test.html ');
Both the $.post and $.get methods pass some parameters to a page processing in the server.
The $.post method is to use post to submit data, which is structured as
$.post (Url[,data][,callback][,type])
URL of the URL request for the HTML page
Data sent to the server by Key/value
Callback callback function when the request is complete, whether the request succeeds or fails
The format returned by the type server includes XML, HTML, script, JSON, text, and _default
For example:
$.post (' test.php ', {
Text: ' My string ',
Number:23
}, function () {
Alert (' Your data has been saved. ');
});
The $.get method is to use get to submit the data, which is structured as
$.get (Url[,data][,callback][,type])
URL of the URL request for the HTML page
Data sent to the server by Key/value
Callback callback function when the request is complete, whether the request succeeds or fails
The format returned by the type server includes XML, HTML, script, JSON, text, and _default
$.get (' test.php ', {
Text: ' My string ',
Number:23
}, function () {
Alert (' Your data has been saved. ');
});