ARInterceptor.js - An open source ajax requests interceptor.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
ARInterceptor.js
ARInterceptor.min.js
LICENSE
README.md
gulpfile.js
index.html
package.json

README.md

ARInterceptor — 开源的 AJAX 拦截器

How to Use? 开始拦截

将 ARInterceptor.js 放到您希望进行 AJAX 请求拦截的页面,HTML代码如下:

Deploy file "ARInterceptor.js" in the page which you want to intercept all the ajax requests from here:

<script src="ARInterceptor.js"></script>

接下来,您就可以进行 ARInterceptor 的初始化,开始拦截页面发送的所有 AJAX 请求了,初始化代码如下:

Next, you can initial "ARInterceptor" and start intercepting all the ajax requests from this page like below:

	// Init ARInterceptor
	var aRInterceptor = new ARInterceptor({
        __GET_processCallback: function(dataBundle){

        	// Dealing with "GET" params

            return dataBundle;

        },
        __POST_processCallback: function(dataBundle){

        	// Dealing with "POST" params

        	return dataBundle;

        },
    });

在上述代码中,您只需要添加并关注两个方法 __GET_processCallback__POST_processCallback。在这两个方法中会分别返回改 AJAX 请求的 POST 和 GET 参数,你可以对这些参数进行验证,或者添加新的参数或去掉一些参数。返回的参数 dataBundle 会被直接发送;

You just only need to focus on two standard methods __GET_processCallback and __POST_processCallback, "ARInterceptor" will return you "GET" parameters as dataBundle in method __GET_processCallback and also return you "POST" parameters in method __POST_processCallback. You can deal with these data in anyway you want (validation, remove parts of params or add extra params and etc).

    // Init ARInterceptor
    var aRInterceptor = new ARInterceptor({
        __GET_processCallback: function(dataBundle){

            // Dealing with "GET" params

            return false;

        },
        __POST_processCallback: function(dataBundle){

            // Dealing with "POST" params

            return false;

        },
    });

如果您在任意一个方法里返回了 false, 该次 AJAX 请求将被终止, 并在 Console 中提示错误;

If you return false in one of there two methods, this ajax request will be cancelled.

*每一个 dataBundle 类型都是一个含有键值对的 JS 对象。

*Every dataBundle is an Object type with key-value pairs.