我正在尝试在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');
}
});
}
答案 0 :(得分: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();
}
});
}
答案 1 :(得分:2)
你不能把一个函数放在ready
块中:
function something() {
alert('hi');
}
$(document).ready(function() {
something();
});
然后再打电话给它?