Question

I am using Cache Server Page (Intersystems) and trying to call ASHX through javascript, but it doesn't work.

How do I call ashx written in c# in cache server pages ?

I tried to to use the following method.

Intersystems Cache

    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
}

}
Was it helpful?

Solution

If I understand you correctly, you just want to call ASHX from a client side JavaScript.

If so, it is no CSP problem at all. The page could be generated by JSP or PHP with the same result, a HTML page. The problem probably lies somewhere in your JavaScript code. Try some tutorials on ASHX, or find some ready-made AJAX solution.

Since it's a CSP page, it doesn't have to be static. You should better use some Caché ObjectScript code to generate repeated code and insert some content from the database. For example:

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>
    >
}

This generates three rows with Value no.1 to Value no.3 labels.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top