【发布时间】:2010-08-31 04:50:50
【问题描述】:
我在将使用 AJAX 获得的函数结果与该函数同步时遇到问题。 这个想法是我发送 AJAX 请求,然后在收到答案后打开对话框,并在用户确认函数返回正确的值后。问题是我的函数(即使我将 ajax 请求设置为不异步)在捕获用户操作之前不会等待响应并返回值。 这是一个代码:
checkColisions = function(event) {
var parsedStart = Date.parse(event.start);
var parsedEnd = Date.parse(event.end);
var returnValue = true;
returnValue = $.ajax({
async: false,
url: '<?php echo url_for('lecture/ajaxCheckColisions')?>',
data: ({id: event.eid, name:event.title, start: parsedStart, end: parsedEnd}),
success: function(data) {
if(data == 'no-colisions')
{
returnValue = false; //do nothing
}
else
{
$("#dialog-colisions").dialog({
resizable: false,
open: function() {
$('#dialog-colisions').text()
$('#dialog-colisions').append('<p>Found colisions:</p>');
$('#dialog-colisions').append(data);
},
height:300,
modal: true,
buttons: {
'Continue': function(){
$(this).dialog('close');
returnValue = false;
},
'Cancel': function() {
$(this).dialog('close');
returnValue = true;
}
}
});
}
},
error: function(data) {
alert('error' +data);
}
});
return returnValue;
};
enter code here
returnValue 应该由对话框设置,但不是。 你有什么想法吗?
【问题讨论】:
标签: jquery ajax jquery-ui jquery-ui-dialog