码迷,mamicode.com
首页 > Web开发 > 详细

jquery get-post请求

时间:2017-10-09 23:59:11      阅读:413      评论:0      收藏:0      [点我收藏+]

标签:asp   ica   手册   out   before   方式   www   dcl   aaa   

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

     jQuery - AJAX get() 和 post() 方法 w3c

     jQuery中ajax的4种常用请求方式

     jQuery调用ajax请求的常见方法汇总

jquery get-post请求

标签:asp   ica   手册   out   before   方式   www   dcl   aaa   

原文地址:http://www.cnblogs.com/zhen-android/p/7643394.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!