ASP.NET 简单的 JSON 处理实现 Ajax 功能

2015-04-07 0 221
ASP.NET 简单的 JSON 处理实现 Ajax 功能
var ajax = {

    setDebugMode: function(){
        this.debugMode = true;
    },

    get: function (requestUrl, data, loaderImageId, onSuccess, onComplete) {

        if (loaderImageId) {
            $("#" + loaderImageId).css('display', 'inline');
        }

        var completeFunction = function () {
            if (onComplete) {
                onComplete();
            }
            if (loaderImageId) {
                $("#" + loaderImageId).css('display', 'none');
            }
        };

        $.ajax({
            type: "GET",
            url: requestUrl,
            data: data,
            context: this,
            success: function (response) {
                onSuccess(response);
                completeFunction();
            },
            error: function (response) {
                alert("Ajax Request Failed");
                this.showError(response);
                completeFunction();
            }
        });
    },

    post: function (requestUrl, data, loaderImageId, onSuccess, onComplete) {

        if (loaderImageId) {
            $("#" + loaderImageId).css('display', 'inline');
        }

        var completeFunction = function () {
            if (onComplete) {
                onComplete();
            }
            if (loaderImageId) {
                $("#" + loaderImageId).css('display', 'none');
            }
        };

        $.ajax({
            type: "POST",
            url: requestUrl,
            context: this,
            data: data,
            success: function (response) {
                onSuccess(response);
                completeFunction();
            },
            error: function (response) {
                alert("Ajax Request Failed");
                this.showError(response);
                completeFunction();
            }
        });
    },

    showError: function(requestObject){
        if (this.debugMode){
            alert(requestObject.responseText);
        }
    }
};

遇见资源网 ASP/Basic ASP.NET 简单的 JSON 处理实现 Ajax 功能 http://www.ox520.com/13407.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务