开发者

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

开发者 https://www.devze.com 2022-12-31 00:51 出处:网络
Is it possible to 开发者_JAVA百科call a handler using javascript code? e.g. i have a handler deployed at this location http://mysitename.com/getMyData.ashx. Can I call this handler or just request it

Is it possible to 开发者_JAVA百科call a handler using javascript code? e.g. i have a handler deployed at this location http://mysitename.com/getMyData.ashx. Can I call this handler or just request it using javascript? Is it even possible or not? Please suggest.


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();
}


You can use XMLHttpRequest (AJAX, not necessarily using XML) to load an URL in the background. I'd highly suggest you to do it through a javascript framework like jQuery since that saves you from accessing the ugly low-level interface directly.


First of please elaborate a bit what are you trying to do.

You can call it with AJAX and request the webservice URL.


$(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

精彩评论

暂无评论...
验证码 换一张
取 消