ajaxJson(常用)

2018-06-24 01:13:11来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

function ajaxJson(method, url, data, callback) {
    var options = {
        type: method,
        url: url,
        dataType: 'JSON',
        traditional: true,
        contentType: "application/json; charset=utf-8"
    };
    if (typeof data === 'function') { // No data offered
        callback = data;
    } else { // Add data
        options.data = data;
    }
    options.success = function (msg) {
        return callback(null, msg);
    };
    options.error = function (err) {
        return callback(err);
    };
    $.ajax(options);
}

  

ajaxJson('POST', url, JSON.stringify(param), function(err, result){
  //result or rsp

  // if(SUCCESS){

  //.......  

  }else{

  //.......

  }
});

 

——————————————————————————————————————————————————————————————————————

 

//DateTables (ajax) 异步获取数据填充到表格显示(ajax)

        ajax: function (data, callback, settings) {
            //封装请求参数
            var param = {
                "page": {

                }
            };
            $.ajax({
                type: "POST",
                url: url,
                data: JSON.stringify(param),
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    //......
                    callback(returnData);
                }
            });
        }

  _____________________________________________________________________________________________________________________________

    var options = {
        url: url,
        type: 'POST',
        data: data,
        processData: false,
        contentType: false,
        success: function (rsp) {
            if(rsp.code==200){
                  ....  
            }else{
                  ....
            }
        },
        error: function (e) {
            //......
        }
    };
    $.ajax(options);

  //----------------------------------------

    $.ajax({
        type: "POST",
        url: webroot + "/ht/uploadAndSaveFile",
        data: JSON.stringify(params),
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        success: function(rsp) {
            console.log(rsp)
            // if (rsp.code == 200) {
            //     if (paramsId == '') {
            //         hint("添加成功");
            //     } else {
            //         hint("修改成功");
            //     }
            //     $("#addCustomerBox").modal("hide");
            //     //getCustomerList(1);
            //     loadTalbe();
            //     clearCustomer();
            // } else {
            //     hint(rsp.message);
            // };
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            console.log(rsp)
        }
    });

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:前端学算法之算法复杂度

下一篇:JavaScript对象复制