• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript xmlhttprequest.XMLHttpRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中xmlhttprequest.XMLHttpRequest的典型用法代码示例。如果您正苦于以下问题:TypeScript XMLHttpRequest类的具体用法?TypeScript XMLHttpRequest怎么用?TypeScript XMLHttpRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了XMLHttpRequest类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: dashboardServerReset

        private dashboardServerReset(req: any, res: any) {
            var sessionid = req.params.sessionid;
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = () => {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        res.send("Done.");
                    }
                }
            }

            xhr.open("GET", "http://" + req.headers.host + "/api/reset/" + sessionid);
            xhr.send();
        }
开发者ID:MakotoIshisaka,项目名称:Vorlonjs,代码行数:14,代码来源:vorlon.dashboard.ts


示例2: return

         return (req: any, res: any) => {
             var sessionid = req.params.sessionid;
             var xhr = new XMLHttpRequest();
             xhr.onreadystatechange = () => {
                 if (xhr.readyState === 4) {
                     if (xhr.status === 200) {
                         res.send("Done.");
                     }
                 }
             }
 
             xhr.open("GET", "http://" + req.headers.host + this.baseURLConfig.baseURL + "/api/reset/" + sessionid);
             xhr.send();
         }
开发者ID:ToToSe,项目名称:Vorlonjs,代码行数:14,代码来源:vorlon.dashboard.ts


示例3: getInfo

    getInfo(stopcode:number):string {
        try {
            var XMLHttpRequest:any = require("xmlhttprequest").XMLHttpRequest;
            // request('http://www.google.com', function (error, response, body) {
            //     var request = require('google');
            //     if (!error && response.statusCode == 200) {
            //         console.log(body) // Show the HTML for the Google homepage. 
            //     }
            // });

    
        var id = this.busStop.getID(stopcode);
            var url:string = `https://api.tfl.gov.uk/StopPoint/${id}/Arrivals?app_id=&app_key=`;
            var xmlHttp = new XMLHttpRequest();
            xmlHttp.open( "GET", url, false ); // false for synchronous request
            xmlHttp.send( null );
            return xmlHttp.responseText;
        } catch(error) {
            console.log(error);
            return "Error: attempts to acquire information failed";
        }
    }
开发者ID:BenNaccarato,项目名称:BusWire,代码行数:22,代码来源:RequestHandler.ts


示例4: getNearestTwoBusStops

    getNearestTwoBusStops(postcode:string):number[] {
        
        var XMLHttpRequest:any = require("xmlhttprequest").XMLHttpRequest;
        var url:string = "http://api.postcodes.io/postcodes/"+postcode;
        try {
            var xmlHttp = new XMLHttpRequest();
            xmlHttp.open( "GET", url, false );
            xmlHttp.send( null );
            var postcodeInfo:any = JSON.parse(xmlHttp.responseText);
            var eastings:number = postcodeInfo.result.eastings;
            var northings:number = postcodeInfo.result.northings;
            var stopcodes:number[] = [NaN,NaN];

            var bestDistance:number = NaN;
            var secondBestDistance:number = NaN;
            this.busStops.forEach(stop => {
                var info:string[] = stop.split(",");
                var stopEasting:number = parseInt(info[4]);
                var stopNorthing:number = parseInt(info[5]);
                var distanceSquared:number = (eastings - stopEasting)*(eastings-stopEasting) + (northings - stopNorthing)*(northings - stopNorthing);
                if(!isNaN(distanceSquared) && (isNaN(bestDistance) || distanceSquared < bestDistance)) {
                    secondBestDistance = bestDistance;
                    bestDistance = distanceSquared;
                    stopcodes[1] = stopcodes[0];
                    stopcodes[0] = parseInt(info[1]);
                } else {
                    if(isNaN(secondBestDistance) || distanceSquared < secondBestDistance) {
                        secondBestDistance = distanceSquared;
                        stopcodes[1] = parseInt(info[1]);
                    }
                }
            });
            if(isNaN(stopcodes[0])|| isNaN(stopcodes[1]))return null;

            return stopcodes;
        } catch (error) {
            return null;
        }
    }
开发者ID:BenNaccarato,项目名称:BusWire,代码行数:39,代码来源:BusStops.ts


示例5: Promise

    return new Promise(function(resolve, reject) {
        let request = new XMLHttpRequest();

        let timer: any = null;
        timer = setTimeout(() => {
            if (timer == null) { return; }
            timer = null;

            reject(new Error('timeout'));
            setTimeout(() => {
                request.abort();
            }, 0);
        }, timeout);

        let cancelTimeout = () => {
            if (timer == null) { return; }
            clearTimeout(timer);
            timer = null;
        }

        if (json) {
            request.open('POST', url, true);
            headers['content-type'] = { key: 'Content-Type', value: 'application/json' };
        } else {
            request.open('GET', url, true);
        }

        Object.keys(headers).forEach((key) => {
            let header = headers[key];
            request.setRequestHeader(header.key, header.value);
        });

        request.onreadystatechange = function() {
            if (request.readyState !== 4) { return; }

            if (request.status != 200) {
                cancelTimeout();
                // @TODO: not any!
                let error: any = new Error('invalid response - ' + request.status);
                error.statusCode = request.status;
                if (request.responseText) {
                    error.responseText = request.responseText;
                }
                reject(error);
                return;
            }

            let result: any = null;
            try {
                result = JSON.parse(request.responseText);
            } catch (error) {
                cancelTimeout();
                // @TODO: not any!
                let jsonError: any = new Error('invalid json response');
                jsonError.orginialError = error;
                jsonError.responseText = request.responseText;
                if (json != null) {
                    jsonError.requestBody = json;
                }
                jsonError.url = url;
                reject(jsonError);
                return;
            }

            if (processFunc) {
                try {
                    result = processFunc(result);
                } catch (error) {
                    cancelTimeout();
                    error.url = url;
                    error.body = json;
                    error.responseText = request.responseText;
                    reject(error);
                    return;
                }
            }

            cancelTimeout();
            resolve(result);
        };

        request.onerror = function(error) {
            cancelTimeout();
            reject(error);
        }

        try {
            if (json != null) {
                request.send(json);
            } else {
                request.send();
            }

        } catch (error) {
            cancelTimeout();
            // @TODO: not any!
            let connectionError: any = new Error('connection error');
            connectionError.error = error;
            reject(connectionError);
        }
//.........这里部分代码省略.........
开发者ID:ethers-io,项目名称:ethers-wallet,代码行数:101,代码来源:web.ts


示例6: setTimeout

 setTimeout(() => {
     request.abort();
 }, 0);
开发者ID:ethers-io,项目名称:ethers-wallet,代码行数:3,代码来源:web.ts


示例7:

 Object.keys(headers).forEach((key) => {
     let header = headers[key];
     request.setRequestHeader(header.key, header.value);
 });
开发者ID:ethers-io,项目名称:ethers-wallet,代码行数:4,代码来源:web.ts



注:本文中的xmlhttprequest.XMLHttpRequest类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript xpath.useNamespaces函数代码示例发布时间:2022-05-25
下一篇:
TypeScript xmldom.DOMParser类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap