日期:2014-05-16 浏览次数:20519 次
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; }
<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>