function http(method, url, data, onSuccess, onFailure) {
            var qs = [], xhr;
            if (Util.ENV.Node.JS) {
                xhr = require('./xhr').create();
            }
            else if ('undefined' != typeof XDomainRequest) {
                xhr = new XDomainRequest();
                xdrs.push(xhr);
            }
            else
                xhr = new XMLHttpRequest();
            xhr.onload = function () {
                try {
                    var resp = JSON.parse(xhr.responseText);
                    if ('reason' in resp)
                        throw new Error(resp['reason']);
                    if ('status' in xhr && 200 != xhr.status)
                        throw new Error(xhr.statusText);
                    onSuccess(resp);
                }
                catch (error) {
                    onFailure(error, xhr.status);
                }
            };
            xhr.onprogress = function () {
                //
            };
            xhr.onerror = function (event) {
                onFailure(event.error);
            };
            xhr.ontimeout = function () {
                onFailure(new Error('Timeout'));
            };
            xhr.open(Method.GET == method ? 'GET' : 'POST', format(url), true);
            Util.each(data, function (value, key) {
                qs.push(key + '=' + encodeURIComponent(value));
            });
            if (qs.length && 'setRequestHeader' in xhr)
                xhr['setRequestHeader']('Content-Type', 'application/x-www-form-urlencoded');
            xhr.send(qs.length ? qs.join('&') : null);
        }
function http(method, url, data, onSuccess, onFailure) {
            var qs = [], xhr;
            if (Util.ENV.Node.JS) {
                xhr = require('./xhr').create();
            }
            else if ('undefined' != typeof XDomainRequest) {
                xhr = new XDomainRequest();
                xdrs.push(xhr);
            }
            else
                xhr = new XMLHttpRequest();
            xhr.onload = function () {
                try {
                    var resp = JSON.parse(xhr.responseText);
                    if ('reason' in resp)
                        throw new Error(resp['reason']);
                    if ('status' in xhr && 200 != xhr.status)
                        throw new Error(xhr.statusText);
                    onSuccess(resp);
                }
                catch (error) {
                    onFailure(error, xhr.status);
                }
            };
            xhr.onprogress = function () {
                
            };
            xhr.onerror = function (event) {
                onFailure(event.error);
            };
            xhr.ontimeout = function () {
                onFailure(new Error('Timeout'));
            };
            xhr.open(Method.GET == method ? 'GET' : 'POST', format(url), true);
            Util.each(data, function (value, key) {
                qs.push(key + '=' + encodeURIComponent(value));
            });
            if (qs.length && 'setRequestHeader' in xhr)
                xhr['setRequestHeader']('Content-Type', 'application/x-www-form-urlencoded');
            xhr.send(qs.length ? qs.join('&') : null);
        }
function http ( method , url , data , onSuccess , onFailure ) { var qs = [ ] , xhr ; if ( Util . ENV . Node . JS ) { xhr = require ( './xhr' ) . create ( ) ; } else if ( 'undefined' != typeof XDomainRequest ) { xhr = new XDomainRequest ( ) ; xdrs . push ( xhr ) ; } else xhr = new XMLHttpRequest ( ) ; xhr . onload = function ( ) { try { var resp = JSON . parse ( xhr . responseText ) ; if ( 'reason' in resp ) throw new Error ( resp [ 'reason' ] ) ; if ( 'status' in xhr && 200 != xhr . status ) throw new Error ( xhr . statusText ) ; onSuccess ( resp ) ; } catch ( error ) { onFailure ( error , xhr . status ) ; } } ; xhr . onprogress = function ( ) { // } ; xhr . onerror = function ( event ) { onFailure ( event . error ) ; } ; xhr . ontimeout = function ( ) { onFailure ( new Error ( 'Timeout' ) ) ; } ; xhr . open ( Method . GET == method ? 'GET' : 'POST' , format ( url ) , true ) ; Util . each ( data , function ( value , key ) { qs . push ( key + '=' + encodeURIComponent ( value ) ) ; } ) ; if ( qs . length && 'setRequestHeader' in xhr ) xhr [ 'setRequestHeader' ] ( 'Content-Type' , 'application/x-www-form-urlencoded' ) ; xhr . send ( qs . length ? qs . join ( '&' ) : null ) ; }
HTTP 请求远端数据。
HTTP 请求远端数据。