我想知道为什么在我的示例 #1 中,警报以正确的顺序 1、2 触发,但在示例 #2 中,我添加了一个 ajax 调用,触发顺序然后变为 2,1。也有人可以建议如何使用 ajax 调用来实现所需的 1、2 触发顺序......我很难过。
示例 #1
uploader.bind('BeforeUpload', function (up, file, policy, sinature) {
//alert('1');
test();
function test() {
alert('1');
}
});
uploader.bind('UploadFile', function (up, file, policy, signature) {
test2();
function test2() {
alert('2');
}
});
示例 #2
uploader.bind('BeforeUpload', function (up, file, policy, sinature) {
//alert('1');
test();
function test() {
data = { alc: 'private', bucket: 'PhotojimaDev', file: file.name, key: path };
$.ajax({
url: sf.getServiceRoot('photojima') + "Upload/getPolicy",
type: 'POST',
data: data,
beforeSend: sf.setModuleHeaders
}).done(function (response, status) {
if (status == "success") {
policy = response.policy;
signature = response.signature;
alert('1');
}
}).fail(function (xhr, result, status) {
alert("Uh-oh, something broke: " + status);
});
}
});
uploader.bind('UploadFile', function (up, file, policy, signature) {
test2();
function test2() {
alert('2');
}
});