Javascript 需要来自TFS/Sharepoint的Ping请求
我将使用Visual Studio 2013制作一个“适用于Windows 8.1的应用商店”,我需要检查tfs服务器是否在线/离线(不是我的服务器,但获得了url,我有一个使用Sharepoint创建和测试某些表的帐户) 我使用HTML/Javascript,用户应该查看服务器是否可以访问。我需要的是使用Javscript或其他东西(ajax?)ping。我还想要一些关于ping时间的信息和一些标题信息。 我为测试创建了一些按钮,稍后将删除它们 HTMLJavascript 需要来自TFS/Sharepoint的Ping请求,javascript,sharepoint,tfs,visual-studio-2013,windows-store-apps,Javascript,Sharepoint,Tfs,Visual Studio 2013,Windows Store Apps,我将使用Visual Studio 2013制作一个“适用于Windows 8.1的应用商店”,我需要检查tfs服务器是否在线/离线(不是我的服务器,但获得了url,我有一个使用Sharepoint创建和测试某些表的帐户) 我使用HTML/Javascript,用户应该查看服务器是否可以访问。我需要的是使用Javscript或其他东西(ajax?)ping。我还想要一些关于ping时间的信息和一些标题信息。 我为测试创建了一些按钮,稍后将删除它们 HTML 如果此服务器没有允许您尝试执行ajax
如果此服务器没有允许您尝试执行ajax请求的cors头,您可以尝试从服务器加载一个不可见的映像,并使用错误的可选url检查映像的url。我不知道如何获得往返时间谢谢,Cors正在工作,我可以登录
var req = new XMLHttpRequest();
// Feature detection for CORS
if ('withCredentials' in req) {
req.open('GET', 'https://tfs.xxx.de/sites/xxx/xxx/xxx.aspx', true);
// Just like regular ol' XHR
req.onreadystatechange = function () {
if (req.readyState === 4) {
if (req.status >= 200 && req.status < 400) {
document.getElementById("response").innerHTML = "Working";
} else {
document.getElementById("response").innerHTML = "Not Working";
}
}
};
req.send();
}
var-req=new-XMLHttpRequest();
//CORS的特征检测
if(请求中的('withCredentials')){
请求打开('GET','https://tfs.xxx.de/sites/xxx/xxx/xxx.aspx",对),;
//就像普通的olxhr一样
req.onreadystatechange=函数(){
如果(req.readyState==4){
如果(请求状态>=200&请求状态<400){
document.getElementById(“响应”).innerHTML=“工作”;
}否则{
document.getElementById(“响应”).innerHTML=“不工作”;
}
}
};
请求发送();
}
(function () {
"use strict";
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
app.onactivated = function (args)
{
if (args.detail.kind === activation.ActivationKind.launch)
{
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated)
{
// TODO: Diese Anwendung wurde neu gestartet. Die Anwendung
// hier initialisieren.
} else {
// TODO: Diese Anwendung war angehalten und wurde reaktiviert.
// Anwendungszustand hier wiederherstellen.
}
args.setPromise(WinJS.UI.processAll().then(function completed()
{
var ok = document.getElementById("button_server_ok");
ok.addEventListener("click", server_ok, false);
var slow = document.getElementById("button_server_slow");
slow.addEventListener("click", server_slow, false);
var off = document.getElementById("button_server_offline");
off.addEventListener("click", server_offline, false);
var ping= document.getElementById("button_ping");
ping.addEventListener("click", ping, false);
}));
}
};
app.oncheckpoint = function (args)
{
// TODO: Diese Anwendung wird gleich angehalten. Jeden Zustand,
// der über Anhaltevorgänge hinweg beibehalten muss, hier speichern. Dazu kann das
// WinJS.Application.sessionState-Objekt verwendet werden, das automatisch
// über ein Anhalten hinweg gespeichert und wiederhergestellt wird. Wenn ein asynchroner
// Vorgang vor dem Anhalten der Anwendung abgeschlossen werden muss,
// args.setPromise() aufrufen.
};
function server_ok(eventinfo)
{
document.getElementById("response").innerHTML = "GREEN";
document.getElementById("server_ok").setAttribute("fill", "#00FF00");
document.getElementById("server_slow").setAttribute("fill", "#FFFFFF");
document.getElementById("server_offline").setAttribute("fill", "#FFFFFF");
}
function server_slow(eventinfo)
{
document.getElementById("response").innerHTML = "YELLOW";
document.getElementById("server_slow").setAttribute("fill", "#FFFF00");
document.getElementById("server_ok").setAttribute("fill", "#FFFFFF");
document.getElementById("server_offline").setAttribute("fill", "#FFFFFF");
}
function server_offline(eventinfo)
{
document.getElementById("response").innerHTML = "RED";
document.getElementById("server_offline").setAttribute("fill", "#FF0000");
document.getElementById("server_ok").setAttribute("fill", "#FFFFFF");
document.getElementById("server_langsam").setAttribute("fill", "#FFFFFF")
}
function ping(eventinfo)
{
}
app.start();
})();
var req = new XMLHttpRequest();
// Feature detection for CORS
if ('withCredentials' in req) {
req.open('GET', 'https://tfs.xxx.de/sites/xxx/xxx/xxx.aspx', true);
// Just like regular ol' XHR
req.onreadystatechange = function () {
if (req.readyState === 4) {
if (req.status >= 200 && req.status < 400) {
document.getElementById("response").innerHTML = "Working";
} else {
document.getElementById("response").innerHTML = "Not Working";
}
}
};
req.send();
}