日期:2014-05-17 浏览次数:20412 次
var options = { dataType: 'json', beforeSubmit: _this.showRequest, //提交前处理 error: _this.showError, //错误处理 success: _this.showResponse //提交成功的处理 }; $("#myForm").ajaxForm(options);
------解决方案--------------------
纯ajax没有办法执行文件上传
你要上传文件必须有一个隐藏的frame 通过这个子frame上传 然后向子写入js代码来通知页面
前台的代码:
<div id="UpLoad_Show"> </div> <script type="text/javascript"> function UpLoadPictureShow(id, ifVertically) { var value = $("#pictures").val(); var img; if (ifVertically == "Vertically") { img = "<img alt='' src='/File/DownLoad/" + id + "' width='90px' height='120px' /> "; } else { img = "<img alt='' src='/File/DownLoad/" + id + "' width='120px' height='90px' /> "; } $("#UpLoad_Show").append(img); if (value == 0) { value = id; } else { value += "," + id; } $("#pictures").val(value); } </script> <div> <form action="/File/UpLoadPicture" method="post" enctype="multipart/form-data" target="UpLoad_Do"> <input name="File1" type="file" /> <input type="submit" value="上传" /> </form> <iframe id="UpLoad_Do" src="../Child/UpLoad.htm" style="display:none"></iframe> </div>