Should breakpoint in the Page_Load event handler b

2020-02-16 03:35发布

问题:

I'm making the following ajax request:

    $.ajax({
    type: 'POST',
    url: 'AJAX.aspx/TestPageLoad',
    data: JSON.stringify({}),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
        alert('Success');
    },
    error: function (x, e) {
        alert( x.responseText);
    }
});

I put a break point in my AJAX.aspx page but it does not get hit. Is it the way it supposed to be? According to this article it does.

回答1:

I put a breakpoint in the Page_Load of my AJAX.aspx page but it does not get hit

It's because the JavaScript executes on DOM Ready.

Doesn't Page_Load event get fired when making ajax calls?

No. It executes after Page life cycle and on DOM ready

For that you have to set the debugger in Ajax call like below

$(document).ready(function () {
    debugger;                     //A kind of Break Point
    $.ajax({
        type: 'POST',
        url: 'AJAX.aspx/TestPageLoad',
        data: JSON.stringify({}),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            alert('Success');
        },
        error: function (x, e) {
            alert(x.responseText);
        }
    });
});