dongyuan1983 2013-07-03 12:59
浏览 39
已采纳

Ajax图像上载会导致Internet Explorer中出现意外输出

I have worked around to make an ajax request for uploading a picture and I have used the below piece of code.

<form id="upload" method="post" action="upload.php" enctype="multipart/form-data">
    <input type="file" name="upl"/>
</form>

<script> // all other jquery dependencies are added for ajax file upload 
$(function(){

      $('#upload').fileupload({
      add: function (e, data) {
           var jqXHR = data.submit();    
        },
      success:function(result){
                alert(result);
     }
  });
});
</script>

My upload.php

<?php if(isset($_FILES['upl'])){
      $file = 'some random name'; // generated using rand functions in php
     if(move_uploaded_file($_FILES['upl']['tmp_name'],$file ))
        echo 'success';
      }
?>

On success I was expecting jQuery to alert success and it works perfectly fine in chrome and other browsers but when it comes to IE 7 it alerts [object Object] as output but I expect it to be success

Where did I make a mistake?

  • 写回答

2条回答 默认 最新

  • doupaoshu8334 2013-07-03 14:56
    关注

    In upload.php, instead of echoing the output using

    echo 'success';
    

    you could return the JSON representation of the object using the function json_encode.

    This way you can parse the json with javascript and use the parsed string in your alert. This method is cleaner than the one you are using and possibly compatible with older versions of IE (you might also need to use the JSON.stringify function to convert the parsed JSON into a string).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序