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

1k views Asked by At

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?

0

There are 0 answers