Jquery $.get call and $.ajax is not working for calling ASHX handler

ぃ、小莉子 提交于 2019-12-24 14:41:20

问题


I have a Asp Button as follow:

<asp:Button ID="btnSubmit" runat="server"  OnClientClick=" if (!ValidateForm()) return false;" PostBackUrl="https://some/website/dot/com"  Class="btn_submit"/>

In my JS, in the middle of ValidateForm() function I need to call a ASHX handler and do some stuff there.

I am using this to call the ASHX file:

$.get("../MasterPages/AHMHandler.ashx?test=1", function (r) {
            alert(r);
        });

But it is not working.

Also I have tried $.ajax as follow and it always alerts error message. How can I see where is the source of error?

$.ajax({
        type: "GET",
        url: "../MasterPages/AHMHandler.ashx?t=1",
        dataType: "HTML",
        success: function (msg) {
            alert(msg);
        },
        error: function () {
            alert("Error");
        }

    });

Any idea???????

Update:

Another weird behavior. The get function is not working in following format:

alert("Before Get call");

        $.get("../MasterPages/AHMHandler.ashx?t=1", function (r) {
            alert(r);
        });

But when I add another alert after the get method, it work and triggers the breakpoint!!!

alert("Before Get call");

        $.get("../MasterPages/AHMHandler.ashx?t=1", function (r) {
            alert(r);
        });

        alert("after Get call");

Any suggestions?

来源:https://stackoverflow.com/questions/18064830/jquery-get-call-and-ajax-is-not-working-for-calling-ashx-handler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!