<script>
        (function ($, undefined) {
            var defaults = {
                'type': 'GET',
                'url': '',
                'data': {},
                'timeout': 60 * 1000 ,// 60秒超時,通常你的服務器端間隔要短于這個時間
                'xhrFields': {
                    'withCredentials': true // 應對跨域的情況
                }
            }
            // options 保持和 $.ajax 的api一致
            $.poll = function (options, fn) {
                function onMessage (data) {
                    alert("onMessage");
                    fn(data)
                    $.poll(options,fn)
                }
                function onError () {
                    alert("onError");
                    // 如果遇到錯誤,就兩秒后重試
                    setTimeout(function(){
                        $.poll(options, fn)
                    }, 2000)
                }
                $.ajax(options)
                        .done(onMessage).fail(onError)
            }
        })(jQuery)

//        // 使用方法:
//
        $.poll({'url': '/server'}, function (data) {
//
            process(data)
//
        })
    </script>