sami_until.js 2.4 KB
//ajax封装
(function ($) {

    $.extend({
        ajaxSend: function (urlSuffix,params) {

            console.log(params);
            var prefixUrl = "http://192.168.1.21/";//仅为测试使用
            // $("head").append('<script src="'+prefixUrl + urlSuffix+'&"></script>');
            return $.ajax({
                url: prefixUrl + urlSuffix,
                type: 'post',
                dataType: 'jsonp',
                async: true,
                //contentType: 'application/json;charset=UTF-8',
                data:params,
                beforeSend: function () {
                }
            }).done(function (data) {
                console.log(data);
            }).fail(function (data) {
            }).always(function () {
            });
        },
        getCookie: function (name) {
            var cookieName = encodeURIComponent(name) + "=";
            var cookieStart = document.cookie.indexOf(cookieName);
            var cookieValue = null;
            if (cookieStart > -1) {
                var cookieEnd = document.cookie.indexOf(";", cookieStart);
                if (cookieEnd == -1) {
                    cookieEnd = document.cookie.length;
                }
                cookieValue = encodeURIComponent(document.cookie.substring(cookieStart + cookieName.length, cookieEnd));
            }
            return decodeURIComponent(decodeURIComponent(cookieValue));
        },
        setCookie: function (name, value, days, path, domain, secure) {
            var cookieText = encodeURIComponent(name) + "=" + encodeURIComponent(value);
            if (days>0) {
                var expires = new Date();
                expires.setTime(expires.getTime() + days * 3600000 * 24);
                //expires.setTime(expires.getTime() + days * 120000);
                var _expires = (typeof days) == "string" ? "" : ";expires=" + expires.toUTCString();
                cookieText = encodeURIComponent(name) + "=" + encodeURIComponent(value)+ _expires + path;
            }
            if (path) {
                cookieText += "; path=" + path;
            }
            if (domain) {
                cookieText += "; domain=" + domain;
            }
            if (secure) {
                cookieText += "; secure"
            }
            document.cookie = cookieText;
        },
        unsetCookie: function (name,days, path, domain, secure) {
            this.setCookie(name, "", days, path, domain, secure);
        }
    })
})(jQuery);