API
var reqUrl = "http://192.168.31.162:8081/obtain/onlineState?name=aa01&password=010203"; /** * 页面 * http://192.168.31.162:8081/http/jquery/Jq01-HttpRequest.html * jquery http get * http://www.cnblogs.com/summers/p/3225375.html */ function testJqueryHttpGet() { debugger; $.get(reqUrl, function (data, status) { console.log(data); console.log(status); }); } /** * jquery http get json */ function testJqueryHttpGetJson() { debugger; $.getJSON(reqUrl, {"height": "1920"}, function (data, status) { console.log(data); console.log(status); }); } var postUrl = "http://192.168.31.162:8081/update/remoteClientInfo"; /** * jquery http post json */ function testJqueryHttpPost() { debugger; var jsonObj = { name: "AAA", pwd: "aaa" }; $.post(postUrl, JSON.stringify(jsonObj), function (data, status) { console.log(data); console.log(status); }, "json", "application/json"); } /** * Ref: * http://www.jb51.net/article/62703.htm */ function testJqueryHttpAjax() { debugger; $.ajax({ type: "post", dataType: "json", contentType: "application/json", timeout: 3000, url: postUrl, data: ‘{"name":"aa01","password":"010203"}‘, success: function (response) { console.log(response); }, error: function (request, errorType, errorMessage) { console.log("[" + errorType + "] " + errorMessage); }, beforeSend: function () { // do something like .addClass(‘is-fetching‘) }, complete: function () { // do something like removeClass(‘is-fetching‘) } }); }
参考:
jQuery - AJAX get() 和 post() 方法 w3c
原文:http://www.cnblogs.com/zhen-android/p/7643394.html