JQuery AJAX and jqueryajax
I. Why JQuery AJAX?
- Because in the Development of AJAX in traditional (js), AJAX has two main problems:
- For browser compatibility issues, writing AJAX code is too troublesome and many of them are the same.
- In actual development, Ajax is usually used by jQuery ajax.
Ii. Ajax APIs of JQuery
$. Get (path, [Request Parameter], [callback function], [data type]); Data Type: string by default
$. Post (path, [Request Parameter], callback function, [data type]); Data Type: string by default
$. GetJSON (url, request parameter, callback function) Application Scenario: when the data returned by the server to the client is of the json type
- Data Type (dataType): "xml ",
"Html ",
"Text ",
"Script ",
"Json ",
"Jsonp"
3. Getting Started
$ ("# Btn1 "). click (function () {// send the request; $. get (url, [params], [function (result) {}]) $. get ("$ {pageContext. request. contextPath}/demo01 ",
{"Username": "zs", "password": "123456 "},
Function (result) {alert (result );});});
$ ("# Btn2 "). click (function () {// send the request; $. post (url, [params], [function (result) {}]) $. post ("$ {pageContext. request. contextPath}/demo01 ",
{"Username": "zs", "password": "123456 "},
Function (result) {alert (result );});});
// From test. js loads JSON data and attaches parameters to display a name field in JSON data. // $. jQuery. getJSON (url, [data], [function (result) {}]) $. getJSON ("test. js ", {name:" John ", time:" 2 "}, function (json) {alert (" JSON Data: "+ json. users [3]. name );});