Ajax-jquery method-Getting Started 01 (finishing), ajax-jquery01
----------------------------------- 7.07.21 write -----------------------------------------
Compared with native javascript, jquery's ajax is easy to understand. One is 100x100, and the other is 1 + 1. Thanks to John Resig.
1 <script type = "text/javascript"> 2 $ (function () {3 $ (". btn "). click (function () {4 var obj = {5 url: "http: // localhost/test.txt", // required. The address 6 type: "GET", // required. Sending Method 7 data: "", // optional. Data sent to the server, which is generally of the Object Type 8 dataType: "text", // optional. Specifies the expected server response data type. Intelligent judgment (xml, json, script, or html) is performed by default ). For jsonp, specify 9 success: function (msg) {// optional. Callback function 10 console. log (msg); 11}, 12 error: function (err) {// optional. Callback Function 13 console. log (err); 14} 15}; 16 $. ajax (obj); 17}); 18}); 19 </script>
Generally, it can be directly copied and used.
Modify the callback function of url, type, data, dataType, and success according to the actual situation.