0

我有一个 ajax 文件上传器插件(Max's File Uploader),我在其中复制并粘贴了代码并进行了一些更改。

下面是一个 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,因为我使用数值而不是字符串值来衡量文件的成功吗?

4

1 回答 1

1

您可以使用 1 和 2而不是使用trueand 。false

  <script language="javascript" type="text/javascript">window.top.stopImageUpload(<?php echo $result ? 1 : 2; ?>, '<?php echo $_FILES['fileImage']['name'] ?>');</script>
于 2012-09-24T16:26:52.953 回答