How to refer http handler file from jQuery ajax under different directory of asp.net web application

后端 未结 1 743
夕颜
夕颜 2021-01-28 01:40

I have a http handler file in following directory of my application

I am referring this handler from common.js file using jQuery ajax and c

1条回答
  •  伪装坚强ぢ
    2021-01-28 02:00

    Instead of relative path (../../Common/Handlers/CommonHandler.ashx), you can start your path from root(/Common/Handlers/CommonHandler.ashx). So it will work for any page:

    function GetMessage(key) {
    var message = '';
    
    $.ajax({
        type: 'POST',
        url: '/Common/Handlers/CommonHandler.ashx', /*Working for EmoloyeeProfile.aspx but not for StoresSummary.aspx*/
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        data: { 'MessageKey': key },
        success: onSucess,
        error: OnFailed,
        async: false
    });
    
    function onSucess(res) {
        message = res;
    }
    
    function OnFailed(res) {
        alert('failed');
    }
    
    return message;
    }
    

    0 讨论(0)
提交回复
热议问题