<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="js/jquery-1.12.4.js"></script> <script> $(function(){ $("#btn").on("click",function(){ $.ajax({ // 后端程序的url地址 url: 'http://wthrcdn.etouch.cn/weather_mini', // 也可以使用method,提交數據的方式,默認是'GET',常用的還有'POST' type: 'get', dataType: 'json', // 返回的數據格式,常用的有是'json','html',"jsonp" data:{ // 設置發送給服務器的數據,如果是get請求,也可以寫在url地址的?后面 "city":'北京' } }) .done(function(resp) { // 請求成功以后的操作 console.log(resp); }) .fail(function(error) { // 請求失敗以后的操作 console.log(error); }); }); }) </script> </head> <body> <button id="btn">點擊獲取數據</button> </body> </html>