我正在使用缓存服务器页面(Intersystems)并尝试通过 javascript 调用 ASHX,但它不起作用。
如何在缓存服务器页面中调用用 c# 编写的 ashx?
我尝试使用以下方法。
系统间缓存
Class ArithematicMean.MeanPage Extends %CSP.Page
{
ClassMethod OnPage() As %Status
{
&html<<html id="arithematicmean">
<head>
<script type="text/javascript" src="external_javascript.js"></script>
<script type="text/javascript" src="MeanCalculation.js"></script>
</head>
<body>
<script language='javascript'>
function mean(array)
{
var Mean = 0, N = 0, MeanPrev = 0, Sum=0, p;
for(var i = 0; i < array.length; i++)
{
++N;
p = parseFloat(array[i]);
if (!isNaN(p)) Sum += p;
MeanPrev = Mean;
Mean += (array[i] - MeanPrev) / N;
}
alert (Sum);
alert(Mean ? Math.round(Mean*10)/10 : 0);
}
var httpReq = null;
function InstructionsImageASHX()
{
httpReq = XMLHttpRequest();
httpReq.open("GET", "InstructionsImage.ashx", true);
alert('hi123');
httpReq.onreadystatechange = XMLHttpRequestCompleted;
httpReq.send(null);
}
// initialize XMLHttpRequest object
function XMLHttpRequest() {
var xmlHttp;
try {
// Opera 8.0+, Firefox, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e) {
// IEBrowsers
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
return false;
}
}
}
return xmlHttp;
}
function XMLHttpRequestCompleted()
{
if (httpReq.readyState == 4)
{
try
{
alert(httpReq.responseText);
}
catch (e)
{
}
}
}
</script>
<center>
<h1> Sum and Arithemetic Mean Calculation for 3 Numbers</h1>
</center>
<table cellpadding="5">
<tr>
<td width="20%">
</td>
<td width="20%">
<label name="lblnumone"> Value One</label>
</td>
<td width="20%">
<input type="text" name="txtnumone" id="txtnumone" runat="server" width="10"/>
</td>
</tr>
<tr>
<td width="20%">
</td>
<td width="20%">
<label name="lblnumtwo"> Value Two</label>
</td>
<td width="20%">
<input type="text" name="txtnumtwo" id="txtnumtwo" runat="server" width="21"/>
</td>
</tr>
<tr>
<td width="20%">
</td>
<td width="20%">
<label name="lblnumthree"> Value Three</label>
</td>
<td width="20%">
<input type="text" name="txtnumthree" id="txtnumthree" runat="server" width="21"/>
</td>
</tr>
<tr>
<td width="20%">
</td>
<td width="20%">
<button id="btnInstructionsImage" onclick= 'InstructionsImageASHX();'>Instructions in Image</button>
</td>
<td width="20%">
<button id="btnCalculate" onclick='alert( mean( [document.getElementById("txtnumone").value,document.getElementById("txtnumtwo").value,document.getElementById("txtnumthree").value] ) );'>Calculate Mean</button>
</td>
<td width="20%">
<img src="InstructionsImage.ashx" height="100" width="200">
</td>
</tr>
</table>
</body>
</html>>
Quit $$$OK
}
}