为JS

时间:2017-11-22 18:44:02

标签: javascript function parameters arguments addeventlistener

我有一个函数(doUpload_reply),里面有eventListeners。我的问题是当我想使用completeHandler_reply我需要指定一个回复ID时。所以我将id作为anonymouse函数中的参数给出了但是对我来说不起作用。我不知道可能是什么问题,或者是否有任何其他解决方案为事件监听器功能提供参数我非常高兴。

代码:
doUpload_reply函数

function doUpload_reply(id,e){
    var file = _(id).files[0];
    if(file.name == ""){
        return false;       
    }
    if(file.type != "image/jpeg" && file.type != "image/gif" && file.type != "image/png" && file.type != "image/jpg"){
        alert("That file type is not supported.");
        return false;
    }
    _("triggerBtn_SP_reply").style.display = "none";
    _("uploadDisplay_SP_reply_"+e).innerHTML = '<img src="images/rolling.gif" width="30" height="30">';
    var formdata = new FormData();
    formdata.append("stPic_reply", file);
    var ajax = new XMLHttpRequest();
    ajax.addEventListener("load", function(event){
        completeHandler_reply.call(this,e);
    }, false ); // Here is the problem when I want to give 'e' as a 
                // parameter for the completeHandler_reply function (e is the id)
    ajax.addEventListener("error", errorHandler_reply, false);
    ajax.addEventListener("abort", abortHandler_reply, false);
    ajax.open("POST", "php_parsers/photo_system.php");
    ajax.send(formdata);
}

有没有办法像我在completeHandler_reply函数中那样通过doUpload_reply传递参数?
completeHandler_reply函数在这里:

function completeHandler(event){
    var data = event.target.responseText;
    var datArray = data.split("|");
    if(datArray[0] == "upload_complete_reply"){
        hasImage = datArray[1];
        _("uploadDisplay_SP").innerHTML = '<img src="tempUploads/'+datArray[1]+'" class="statusImage" />';
    } else {
        _("uploadDisplay_SP").innerHTML = datArray[0];
        _("triggerBtn_SP").style.display = "block";
    }
}

我的控制台出现了JS错误: Uncaught TypeError:无法读取未定义的属性'responseText'     在XMLHttpRequest.completeHandler_reply(user.php?u = Frankli Mark&amp; pn = 1:1087)     在XMLHttpRequest。 (user.php?u = Frankli Mark&amp; pn = 1:1078)

0 个答案:

没有答案