使用以下代码,Firebug 控制台中的所有内容都按顺序正常显示,条目按顺序(包括数据的 Ajax 发布),但所有 jQuery 效果/动画(fadeIn
, animate
, slideUp
, slideDown
, animate
, fadeOut
)在在执行实际步骤时不调用我的 Ajax 函数。
为什么要这样做?我如何解决它?
$('#overlay').fadeIn(500, function () {
$('#overlaybox').animate({ 'top': '40px' }, 100);
});
$('#survey').slideUp(1500);
console.log('-after overlay show');
console.log('before ajaxPutSurveyItems()');
ajaxPutSurveyItems(save, after);
console.log('after ajaxPutSurveyItems()');
$('#survey').slideDown(1500);
$('#overlaybox').animate({ 'top': '-200px' }, 300, function () {
$('#overlay').fadeOut(2500);
});
console.log('-after overlay hide');
这是 ajaxPutSurveyItems
function ajaxPutSurveyItems(answers, nextstep) {
console.log('ajaxPutSurveyItems()');
var p = {};
p.uniqueid = gUniqueID;
p.answers = answers;
p.pageid = gSurveyPages[gCurrentPageIndex].ID;
p.pageindex = gCurrentPageIndex.toString();
p.surveydefid = gSurveyID;
p.bypass = gIsBypass;
var j = JSON.stringify(p);
$.ajax({
async: false,
type: "POST",
url: "surveydata.asmx/putSurveyItems",
data: j,
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: function(XHR) {
console.log(':beforeSend');
},
success: function (data, status) {
console.log(':success');
// code removed for brevity
},
error: function (XHR, errStatus, errThrown) {
console.log(':error');
// code removed for brevity
}
});
}