使用ajaxfileupload实现上传图片的功能,firefox下功能正常。在ie下报object error
出错的代码如下:
- JScript code
function ajaxFileUpload() { $("#loading") .ajaxStart(function(){ $(this).show(); }) .ajaxComplete(function(){ $(this).hide(); }); $.ajaxFileUpload ( { url:'upload.php?do=upload', secureuri:false, fileElementId:'fileToUpload', dataType: 'json', data:{name:'logan', id:'id'}, success: function (data, status) { if(typeof(data.error) != 'undefined') { if(data.error != '') { alert(data.error+'abc'); }else { document.getElementById('photo').value=data.msg; var node1 = document.getElementById('imgnode1'); var text = "<br><img src='"+data.msg +"' width='130' height='160' >" +"<form name='imgdel' id='imgdel' action='upload.php?do=delete' method='post'>" +"<input type='hidden' name='file' value='"+data.msg +"'><input type='button' onclick='return ajaxFileDelete();' value='删除'></form>"; var node2 = document.getElementById('imgnode2'); [color=#FF0000]node2.innerHTML = text;[/color] } } }, error: function (data, status, e) { alert(e); } } ) return false; }
通过加alert,已经定位到是node2.innerHTML = text;出错。请大家帮忙看下是什么问题。
网页中相关的代码如下:
- HTML code
<tr><th align="right">照片</th><td></td> <td><input name="photo" id="photo" value="" type="hidden" /> <div id="imgnode1"> <input type="file" size=28 name="file" id="fileToUpload" class="input" /> <br /> <input type="button" id="buttonUpload" onclick="return ajaxFileUpload();" value="上传" /> </div> <div id="imgnode2"> </div> </td></tr>
------解决方案--------------------
你看你ID为imgnode2这个div获取到了吗?打个断点看看node2是不是null