【原创】cs+html+js+css模式(六):改造ajax.js,从原来的原生态js修改为依赖于jquery插件

      由于原有的ajax可能在性能上,对于jquery的支持不够并且不够方便,开发人员使用的时候需要知道我们内部指定的后缀文件的设置,基于这个前提我们进行了js的改造

// 使用闭包开发插件
(function($) {
    $.CustomerAjaxDefault = {
        // url地址
        url: '1.xyz',
        // 传入参数信息
        data: '',
        // 命名空间+类名
        nameSpace: '',
        // 方法名
        methodName: '',
        onSuccess: function() {
        },
        onError: function() {
        }
    };

    $.CustomerOrderAjax = function(options) {
        $.CustomerAjax(options);
    };

    $.CustomerConcurrencyAjax = function(options) {

        $.CustomerAjaxDefault.url = "1.abc";

        $.CustomerAjax(options);
    };

    $.CustomerAjax = function(options) {
        options = $.extend($.CustomerAjaxDefault, options);
        $.ajax({
            url: options.url,
            data: options.data,
            contentType: "application/x-www-form-urlencoded",
            headers: { "RemoteInvoke": "MethodInvoke", "TargetType": options.nameSpace, "CallingMethod": options.methodName + '517MethodEnd' },
            type: "POST",
            success: function(data, textStatus, jqXHR) {
                var successObj = $.parseJSON(data);
                if (successObj.code == 200) {
                    options.onSuccess(decodeURIComponent(successObj.message));
                } else {
                    options.onError(decodeURIComponent(successObj.message));
                }
            },
            error: function(jqXHR, textStatus, error) {
                options.onError(error);
            }
        });
    };

})(jQuery);

原文地址:https://www.cnblogs.com/NoRoad/p/3286431.html