应在Page_Load事件处理程序设置断点使得AJAX调用时被击中? [英] Should breakpoint in the Page_Load event handler be hit when making AJAX call?

查看:218
本文介绍了应在Page_Load事件处理程序设置断点使得AJAX调用时被击中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做下面的Ajax请求:

  $阿贾克斯({
    输入:POST,
    网址:'AJAX.aspx / TestPageLoad',
    数据:JSON.stringify({}),
    的contentType:应用/ JSON的;字符集= UTF-8,
    数据类型:JSON
    成功:功能(数据){
        警报(成功);
    },
    错误:函数(X,E){
        警报(x.responseText);
    }
});

我把一个破发点,我AJAX.aspx页,但它并没有被击中。它是它应该是的方式?根据它。

rel=\"nofollow\">
解决方案

  

我把一个断点在我AJAX.aspx页面的Page_Load中,但它确实
  没有撞到


这是因为JavaScript的DOM的准备执行。


  

不Page_Load事件得到AJAX调用时开除了?


没有。之后页面生命周期和DOM准备好

执行

有关,你必须设置Ajax调用调试器像下面

  $(文件)。就绪(函数(){
    调试器; //一种断点
    $阿贾克斯({
        输入:POST,
        网址:'AJAX.aspx / TestPageLoad',
        数据:JSON.stringify({}),
        的contentType:应用/ JSON的;字符集= UTF-8,
        数据类型:JSON
        成功:功能(数据){
            警报(成功);
        },
        错误:函数(X,E){
            警报(x.responseText);
        }
    });
});

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.

解决方案

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

这篇关于应在Page_Load事件处理程序设置断点使得AJAX调用时被击中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆