jquery get-post请求
Posted zhen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jquery get-post请求相关的知识,希望对你有一定的参考价值。
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 get-post请求的主要内容,如果未能解决你的问题,请参考以下文章