0

我正在尝试在 ajax 回调中重新调用文档的 ready() 函数中的代码。这可能吗?

$(document).ready(function() {
  // page initialization functions
  alert('hi');
});

// this gets called from a button click on the screen
function reauth() {
  // logic here omitted for brevity
  $.post("/Base/reauth", $("#reauthForm").serialize(), function(data) {
    if (data.result != null) {
      $(document).ready();  // <-- this does not invoke the alert('hi');
    }
  });
}
4

2 回答 2

3
function sayHi() {
  alert('hi');
}

$(document).ready(function() {
  // page initialization functions
  sayHi();
});


// this gets called from a button click on the screen
function reauth() {
  // logic here omitted for brevity
  $.post("/Base/reauth", $("#reauthForm").serialize(), function(data) {
    if (data.result != null) {
      sayHi();
    }
  });
}
于 2012-05-26T19:36:19.793 回答
2

你不能在ready块内放一个函数吗:

function something() {
   alert('hi');
}

$(document).ready(function() {
   something();
});

然后再打电话?

于 2012-05-26T19:35:13.577 回答