PageSourceSearch

https://www.dingcheng.gov.cn/content/_common/base/js/power.securit…-NeDFzKy4NqA-WcwXnwG7GQS7J55rKlQwwA1P9qfbCQ

js dingcheng.gov.cn collected 2026-10-02 17:06:38 UTC 4,643 bytes, 150 lines download raw bytes

1/**
2 * CSRF
3 */
4
5/*global jQuery: false */
6
7(function ($) {
8    var __requestverificationtoken = '__requestverificationtoken';
9
10    //$.post扩展方法(预防CSRF)
11    $.postPreventCSRF = function (url, data, success, dataType) {
12        data = addToken(data);
13
14        return $.post(url, data, success, dataType);
15    };
16
17    //$.ajax扩展方法(预防CSRF)
18    $.ajaxPreventCSRF = function (options) {
19        options = options || {};
20        options.type = 'post';
21        options.data = addToken(options.data);
22
23        return $.ajax(options);
24    };
25
26    // $.ajax扩展方法(加载表单防伪标记)
27    var csrfOptions = {
28        url: '/Ajax/AjaxPartial',
29        type: 'post',
30        async: false,
31        data: {
32            partialViewName: "表单防伪标记"
33        },
34        success: refreshCsrf
35    };
36    $.refreshCsrf = function (options) {
37        options = options || csrfOptions;
38        return $.ajax(options);
39    };
40
41    pe = window.pe || {};
42    pe.security = {};
43    pe.security.Csrf = {
44        getRequestVerificationToken: function () {
45            var $requestverificationtoken = getToken();
46            if (!$requestverificationtoken) {
47                return '';
48            }
49
50            return __requestverificationtoken + '=' + $requestverificationtoken.val();
51        },
52        getRequestVerificationTokenValue: function () {
53            var $requestverificationtoken = getToken();
54            if (!$requestverificationtoken) {
55                return '';
56            } else {
57                return $requestverificationtoken.val();
58            }
59        }
60    };
61
62    function addToken(data) {
63        data = data || {};
64
65        var $requestverificationtoken = getToken();
66        if (!$requestverificationtoken) {
67            return data;
68        }
69
70        // 兼容IE8
71        if (!Array.isArray) {
72            Array.isArray = function (arg) {
73                return Object.prototype.toString.call(arg) === '[object Array]';
74            };
75        }
76
77        if (Array.isArray(data)) {
78            var isExistsToken = false;
79            $.each(data,
80                function (index, value) {
81                    if (value['name'] && value['name'].toLowerCase() === __requestverificationtoken) {
82                        isExistsToken = true;
83                        return false;
84                    }
85                });
86
87            if (isExistsToken) {
88                return data;
89            }
90
91            data.push({ name: __requestverificationtoken, value: $requestverificationtoken.val() });
92            return data;
93        }
94        var $tokenInput = $('input[name="__RequestVerificationToken"]');
95        var defaultsData = {
96            "__RequestVerificationToken": $tokenInput && $tokenInput.val()
97        };
98
99        if (typeof (data) === "string") {
100            if (data.toLowerCase().indexOf(__requestverificationtoken) > -1) {
101                return data;
102            }
103
104            data += '&' + __requestverificationtoken + '=' + $requestverificationtoken.val();
105            return data;
106        }
107
108        if (typeof (data) === "object") {
109            data = $.extend({}, { __requestverificationtoken: $requestverificationtoken.val() }, data);
110            return data;
111        }
112
113        return data;
114    }
115
116    function getToken() {
117        var $anti_forgery_token_container = $("[data-power-anti_forgery_token_input]");
118        if ($anti_forgery_token_container.length) {
119            var anti_forgery_token_input = $anti_forgery_token_container.data("power-anti_forgery_token_input");
120            return $(anti_forgery_token_input);
121        }
122
123        var $requestverificationtoken = $('input[name="__RequestVerificationToken"]');
124        if ($requestverificationtoken.length) {
125            return $requestverificationtoken;
126        }
127
128        $.refreshCsrf();
129        $requestverificationtoken = $('input[name="__RequestVerificationToken"]');
130        if ($requestverificationtoken.length) {
131            return $requestverificationtoken;
132        }
133
134        console.error("所需的防伪表单字段“__RequestVerificationToken”不存在!请确保表单中包含@Html.AntiForgeryToken()。");
135        return null;
136    }
137
138    function refreshCsrf(data) {
139        var csrfValue = $(data.html).val();
140        if ($('input[name="__RequestVerificationToken"]').length > 0) {
141            $('input[name="__RequestVerificationToken"]')
142                .each(function () {
143                    var $this = $(this);
144                    $this.val(csrfValue);
145                });
146        } else {
147            $('body').append(data.html);
148        }
149    }
150})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.