hee*_*ema 15 jquery jquery-steps
如何根据某些ajax调用的结果控制移动到下一步?data.d以bool值返回
$("#wizard").steps({
onStepChanging: function (event, currentIndex, newIndex) {
var move = false;
if (currentIndex == 2) {
move = false;
$.ajax({
type: 'POST',
url: "Reservation.aspx/SomeFunction",
data: serializeData({ }),
contentType: "application/json",
dataType: 'json',
success: function (data) {
move = data.d;
return true;
},
error: ajaxLoadError
});
}
return move;
},
saveState: true
});
Run Code Online (Sandbox Code Playgroud)
$.ajax({
type: 'POST',
url: "Reservation.aspx/SomeFunction",
async: false,
contentType: "application/json",
dataType: 'json',
success: function (data) {
move = data.d;
return true;
},
error: ajaxLoadError
});
Run Code Online (Sandbox Code Playgroud)
我有同样的问题,我什至想在ajax加载后使用“setStep”来强制步骤,然后最新版本的jquery.steps去掉了“setStep”..
我最终使用了“next”方法,并且必须使用全局触发器来停止 onChanging 事件的无限循环,简而言之,如果 ajax 返回有效数据,我强制向导转到下一步,否则,它停留在当前步骤,这是代码
var $stopChanging = false;
.... ....
onStepChanging: function (event, currentIndex, newIndex) {
if ($stopChanging) {
return true;
} else {
items = $.ajax({
type: 'POST',
url: "Reservation.aspx/SomeFunction",
data: serializeData({ }),
contentType: "application/json",
dataType: 'json',
success: function (data) {
$stopChanging = true;
wizard.steps("next");
},
error: ajaxLoadError
});
},
onContentLoaded: function (event, currentIndex) {
$stopChanging = false;
}
}
Run Code Online (Sandbox Code Playgroud)
逻辑是这样的:
每次触发两个 onStepChanging 事件听起来不是一个好主意,但这就是我现在可以拥有的
您可能需要为不同的步骤索引行为添加更多条件
小智 5
您可以将 Samy 的方法与同步 ajax 请求结合使用
$("#wizard").steps({
onStepChanging: function (event, currentIndex, newIndex) {
if (currentIndex == 2) {
var requestResult = $.ajax({
type: 'POST',
url: "Reservation.aspx/SomeFunction",
async: false,
contentType: "application/json",
dataType: 'json',
error: ajaxLoadError
});
return requestResult.responseJSON.Result == "/*your expected value*/"
}
},
saveState: true
});
Run Code Online (Sandbox Code Playgroud)