1

我尝试从 Andrew Valums 制作 Ajax 上传器,我知道我需要的只是帮助接收来自上传处理器文件的响应。有没有办法让它完成?

这是JavaScript源

$(function(){
var btnUpload=$('#upldbutton');
var status=$('#status');
new AjaxUpload(btnUpload, {
    action: 'upload-file-cart.php?upldid=<? if($item=='add'){ if($geterr==1){ echo $categories_posthash; }else{ echo $token; }} else{ if($pg=='blogs'){ echo $post_blg_cnt_hash; } else { echo $prod_prod_hash; }} ?>',
    name: 'uploadfile',
    dataType: 'json',
    onSubmit: function(file, ext){
        if (! (ext && /^(jpg|jpeg)$/.test(ext))){
            alert('Only JPEG files allowed for upload!');
            return false;
        }
        status.html('<div id="msgbox3" style="margin-left: 2px; width: 351px; position: absolute; z-index: 2;"><img src="resources/template/img/warning-icon.png" width="16" height="16" alt="err_orng" style="position: absolute; margin-left: -25px; margin-top: -1px;" />WARNING: Upload in progress! <b>Please wait!</b></div>');
    },
    onComplete: function(responseJSON){
        status.text('');
        var errormessage = responseJSON["errormessage"];
        var filename = responseJSON["filename"];
        if(errormessage==="success"){
            $('<li></li>').appendTo('#files').html('<a class="img-delete delete" href="#" onclick="nos_dz(\''+filename+'\');"></a> <a class="fancyimg" href="<? echo $content_path; ?>'+filename+'"><img src="<? echo $content_path; ?>/'+filename+'" alt="" width="82" height="82" /></a>').addClass('upldimages success');
            $('#failupload').hide();
            $(function() {
                $(".delete").click(function() {
                    var upldimages = $(this).parent();
                    var id = $(this).attr("id");
                    var string = 'id='+ id ;

                    $.ajax({
                        type: "POST",
                        success: function(){
                            upldimages.fadeOut('slow', function() {$(this).remove();});
                        }
                    });
                    return false;
                });
            });
            alert('Success!');
        }
        else if(errormessage=="exist"){
            $('<li style="position: absolute; margin-left: 115px; margin-top: -19px;" id="failupload"></li>').appendTo('#files').text(filename).addClass('error');                  
        }
        else {
            $('<li></li>').appendTo('#files').text(filename).addClass('error');
        }
    }
});
});
4

0 回答 0