这是一个不错的小 ajax 上传片段,它将在成功上传或文件太大时通过 ajax 返回消息……诸如此类。在 upload.php Iis 中,我有包含返回到表单页面的消息的 div。我想知道如何修改它,以便将 div/消息返回到模式窗口,而不是仅仅返回到页面本身......希望有人可以帮助我。我需要在某处使用 jquery ui 吗?多谢你们!
$j(document).ready(function(){
var upload = new AjaxUpload('#userfile', {
//upload script
action: '/modules/mod_artuploader/upload.php',
onSubmit : function(file, extension){
//show loading animation
//$j("#loading").show();
//check file extension
if (! (extension && /^(jpg|png|jpeg|gif)$/.test(extension))){
// extension is not allowed
$j("#loading").hide();
$j("<span class='error'>Error: Not a valid file extension</span>").appendTo("#file_holder #errormes");
// cancel upload
return false;
} else {
// get rid of error
$j('.error').hide();
}
//send the data
upload.setData({'file': file, 'userid': <?php echo $user->id?> });
},
onComplete : function(file, response){
//hide the loading animation
$j("#loading").hide();
$j("#userfile").hide();
$j('label[for="userfile"]').hide();
//add display:block to success message holder
$j(".success").css("display", "block");
$j(".picture").css("display", "block");
//This lower portion gets the error message from upload.php file and appends it to our specifed error message block
//find the div in the iFrame and append to error message
var oBody = $j(".iframe").contents().find("div");
//add the iFrame to the errormes td
$j(oBody).appendTo("#file_holder #errormes");
}
});
});
</script>