1

我正在使用缓存服务器页面(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
}

}
4

1 回答 1

0

如果我理解正确,您只想ASHX从客户端调用JavaScript

如果是这样,那完全没有CSP问题。该页面可以由JSPPHP具有相同结果的HTML页面生成。问题可能出在您的JavaScript代码中。尝试一些教程ASHX,或找到一些现成的AJAX解决方案。

因为它是一个CSP页面,所以它不必是静态的。您最好使用一些Caché ObjectScript代码来生成重复代码并从数据库中插入一些内容。例如:

for i=1:1:3 {
    &html< 
        <tr>
            <td><label>Value no.#(i)#</label></td>
            <td><input type="text" name="value#(i)#" id="value#(i)"></td>
        </tr>
    >
}

Value no.1这会生成带有toValue no.3标签的三行。

于 2013-06-05T11:30:53.030 回答