0
我有一个ajax文件上传插件(Max's File Uploader),我复制并粘贴代码并做了一些改动。我是否需要更改JavaScript代码以包含数值?
现在下面是一个jQuery代码,如果该文件是成功,失败或取消的地方措施:
function stopImageUpload(success, imagefilename){
var result = '';
imagecounter++;
var replaceForm = function(result) {
$(sourceImageForm).find('.imagef1_upload_form').html(result + '<label>Image File: <input name="fileImage" class="fileImage" type="file"/></label><br/><br/><label><input type="submit" name="submitImageBtn" class="sbtnimage" value="Upload" /></label><label><input type="button" name="imageClear" class="imageClear" value="Clear File"/></label>');
}
var updateForm = function(result) {
$(sourceImageForm).find('.imagef1_upload_form').find('.display_content_image').html(result);
}
var displayInfo;
if (success === 1){
result = '<span class="imagemsg'+imagecounter+'">The file was uploaded successfully</span><br/><br/>';
$('.listImage').eq(window.lastUploadImageIndex).append('<div>' + htmlEncode(imagefilename) + '<button type="button" class="deletefileimage" image_file_name="' + imagefilename + '">Remove</button><br/><hr/></div>');
displayInfo = replaceForm;
}
else if (success === 2){
result = '<span class="imagemsg'+imagecounter+'"> The file upload was canceled</span><br/><br/>';
displayInfo = updateForm;
}
else {
result = '<span class="imagemsg'+imagecounter+'">There was an error during file upload</span><br/><br/>';
displayInfo = updateForm;
}
displayInfo(result);
)};
但我有一个JavaScript函数,其中它输出在PHP脚本下面这样:
<script language="javascript" type="text/javascript">
window.top.stopImageUpload(<?php echo $result ? 'true' : 'false'; ?>, '<?php echo $_FILES['fileImage']['name'] ?>');
</script>
但是,我的问题是,它在上面说'真'或'假'的地方,应该是1:2,因为我使用数字值而不是字符串值来衡量文件的成功吗?
看一下上面的代码,是的,它必须是'1'或者'2'。但是,因为您只是将它用作布尔值,所以应该重构它。 –