0

我需要帮助!!

我有以下onSubmit文件上传代码:

function uploadFile() {
    var file = _("file1").files[0];
    var formdata = new FormData();
    formdata.append("file1", file);
    var ajax = new XMLHttpRequest();
    ajax.upload.addEventListener("progress", progressHandler, false);
    ajax.addEventListener("load", completeHandler, false);
    ajax.addEventListener("error", errorHandler, false);
    ajax.addEventListener("abort", abortHandler, false);
    ajax.open("POST", "php_parsers/file_upload_parser.php");
    ajax.send(formdata);
}

function completeHandler(e) {
    var fileDest = e.target.responseText; //file location is responseText
    _("uloadedImg").src=fileDest;         // '_' is getelementbyid function
    $('#sesame').bPopup();
}

我在对象上初始化 JCrop,如下所示:

jQuery(function($) {
        $('#uloadedImg').Jcrop();
    });

HTML 是:

<div id="sesame" style="display:none">
<img src="" id="uloadedImg">
</div>

由于某种原因,当我测试此代码时,图像标签变成:

<img src="user/admin/default_avatar.jpg" id="uloadedImg" style="display: none; visibility: hidden; width: 0px; height: 0px;">

我不明白是什么将style元素放在图像标签中,但当我从 chrome 开发工具中删除这些元素时,JCrop 也不起作用。

如果我不能让它工作,我将把我的笔记本电脑扔到墙上。:(

4

1 回答 1

1

考虑到我对这个问题的压倒性反应,我想我会分享出了什么问题!

jcrop在我在那里有图像之前,我正在对图像标签进行初始化。我将jcrop脚本的一部分移到了 ajax 响应中,如下所示:

function uploadFile() {
    var file = _("file1").files[0];
    var formdata = new FormData();
    formdata.append("file1", file);
    var ajax = new XMLHttpRequest();
    ajax.upload.addEventListener("progress", progressHandler, false);
    ajax.addEventListener("load", completeHandler, false);
    ajax.addEventListener("error", errorHandler, false);
    ajax.addEventListener("abort", abortHandler, false);
    ajax.open("POST", "php_parsers/file_upload_parser.php");
    ajax.send(formdata);
}

function completeHandler(e) {
    var fileDest = e.target.responseText; //file location is responseText
    _("uloadedImg").src=fileDest;         // '_' is getelementbyid function
    jQuery(function($) {
        $('#uloadedImg').Jcrop();
    });
    $('#sesame').bPopup();
}

谢谢大家的帮助!

于 2014-02-17T21:29:07.163 回答