您好,登錄后才能下訂單哦!
js代碼 function submitform() { $("#form_upload").ajaxSubmit({ success: showResponse }); } function showResponse(responseText) { if (responseText != null) { alert('上傳成功!'); } else { alert('操作失敗!'); } } $(function () { $("#upImg").on("change", function () { var file = this.files[0]; if (this.files && file) { var reader = new FileReader(); reader.onload = function (e) { $('#result').attr('src', e.target.result); } reader.readAsDataURL(file); } }); })
前臺(tái)代碼 <table> <tr> <td >生產(chǎn)(經(jīng)營(yíng))許可證證件照片</td> <td> <form id="form_upload" action="Upload" target="iframeInfo" method="post" enctype="multipart/form-data"> <input name="upImg" id="upImg" type="file" /> <input type="submit" value="上傳" /> </form> </td> </tr> <tr> <td> <img id="result" src="" alt=""> </td> <td> <iframe name="iframeInfo" id="iframeInfo" ></iframe> </td> </tr> </table> (這里添加iframe,因?yàn)楹笈_(tái)返回時(shí)會(huì)跳轉(zhuǎn),把form放入iframe里提交就不會(huì)跳轉(zhuǎn)頁(yè)面)
后臺(tái)代碼 [HttpPost] public ActionResult Upload(HttpPostedFileBase upImg) { if (upImg == null) { return Content("文件上傳錯(cuò)誤,請(qǐng)重新選擇文件!"); } string fileName = System.IO.Path.GetFileName(upImg.FileName); string filePhysicalPath = Server.MapPath("~/credp_w_picpaths/" + fileName); try { upImg.SaveAs(filePhysicalPath); Session["ImgPath"] = filePhysicalPath; return Content("上傳成功"); } catch { return Content("上傳異常 !"); } }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。