Can I call / request .net handler (ashx) using javascript?

Is it possible to call a handler using javascript code? for example, I have a handler deployed at this location http://mysitename.com/getMyData.ashx . Is it possible to call this handler or just request it using javascript? Is this possible or not? Please suggest.

+3
source share
4 answers

Yes, you can

use ajax or jquery ajaxcall for this.

same ajax function:

function showHint(elementid,url,str) {

    if (window.XMLHttpRequest) {
        xmlhttp=new XMLHttpRequest();
    } else {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            document.getElementById(elementid).innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET",url+str,true);
    xmlhttp.send();
}
+5
source

XMLHttpRequest (AJAX, XML) URL- . javascript-, ​​ jQuery, .

+1

First of all, specify a little what you are trying to do.

You can call him using AJAX and request the web service url.

0
source
$(document).ready(function () {
        saveCookies('true');
    });

function saveCookies(save) {
        $.ajax({
            url: "/Handlers/getMyData.ashx.ashx",
            data: { 'savecookies': save },
           async: false,
            success: function (data, status, xhr) {   
            }
        });
    };
0
source

Source: https://habr.com/ru/post/1746139/


All Articles