ajax raw 请求数据

提交接口数据,接口方提供的是post请求,body - raw ; 

不说废话,直接上代码吧

this.ajax = function (url, method, data) {
    var deferred = $.Deferred();
    data = JSON.stringify(data);
    showWaiting();
    var reqOption = {
        url: url,
        data: data,
        type: method,
        headers: {'Content-Type':'application/json'},
        timeout: 45000,
        async: true,
        cache: false,
        beforeSend: function (xhr, settings) {
        },
        success: function (reqdata, status, xhr) {
            // reqdata = JSON.parse(reqdata);
            // alert(reqdata);
            hideWaiting();
            if (!reqdata.responsecode || reqdata.responsecode == "0"){
                return deferred.reject(reqdata);
            }else {
                return deferred.resolve(reqdata);
            }
        },
        error: function (xhr, errorType, error) {
            var err = {xhr: xhr, errorType: errorType, error: error};
            hideWaiting();
            if (error != null) {
                deferred.reject(error)
            } else {
                deferred.reject(error);
                showToast(err.errorType + ",请稍后重试", 1500)
            }
        },
        complete: function (xhr, status) {
            hideWaiting()
        }
    };

你可能感兴趣的:(ajax raw 请求数据)