我有一个流程,在该流程中我创建了一个轮询函数,该函数通过VBScript执行XMLHttpRequest.
该请求获取一个ASP Classic页面,该页面判断MSSQL表中是否有新插入的记录,并运行一些API以将用户添加到Azure AD.
我使用jQuery进行轮询,然后我使用Windows任务管理器每5分钟运行一次VBScript.代码如下:
-VBSCRIPT:
set xmlhttp = createobject("microsoft.xmlhttp")
xmlhttp.open "GET", "https://myserver.com/polling.asp?route=create-ad-account", false
xmlhttp.send
set xmlhttp = nothing
GET请求中的ASPclassic 代码:
...
action = request("action")
route = request("route")
openDB()
select case action
case "create-ad-account" : createADAccount()
case else : default()
end select
closeDb()
...
function createADAccount()
''Checks table for new records, add to AD accordingly.
...
end function
function default()
%>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
//Get route
var route = getUrlVars()["route"];
//Autorun
if(route!=''){
doPoll('?action=' + route);
}
function doPoll(url) {
var result;
$.post(url, function(data) {
result = data;
})
.done(function (){
console.log(result); //Show results here
if(result!=''){
setTimeout(doPoll(url),1000);
} else {
console.log('Task competed');
}
})
.fail(function (jqXHR, textStatus, errorThrown){
console.log('Error: ' + textStatus);
})
}
function getUrlVars(){
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
</script>
<%
end function
GET请求中的页面判断USERS表中新添加的记录,然后判断AD中是否存在该用户,如果不存在,则通过API调用添加这些记录.
当从浏览器加载页面时,这一切都运行得很好,当从任务调度程序运行页面时,它报告0x0,这意味着成功执行,但没有执行任何操作.
我假设当我try 直接运行VB脚本时,从VB脚本运行时,默认()函数中的JavaScript没有执行,并且没有执行任何操作(即,createADAccount函数不运行).