首页 > 代码库 > ajax 上传图片
ajax 上传图片
html:
<input type="file" id="img1" name="img1" /> <input type="file" id="img2" name="img2" /> <button id="btn_submit">multipart/form-data 提交</button>
javascript:
<script> $(function () { $(‘#btn_submit‘).click(function () { var formdata = http://www.mamicode.com/new FormData(); formdata.append("submittype", "Phone_addMN"); formdata.append("glsort2", "256"); formdata.append("content", "哈哈哈哈啊"); formdata.append("channel", "街拍"); formdata.append("lng", "123"); formdata.append("lat", "121"); formdata.append("file1", $(‘#img1‘)[0].files[0]); formdata.append("file2", $(‘#img2‘)[0].files[0]); $.ajax({ url: "xxxxxxxx.ashx", type: ‘POST‘, data: formdata, dataType: ‘JSON‘, processData: false, contentType: false, success: function (result) { if (result.state) { var n = ""; } else { } } }); }); }); </script>
C#:
var model_submit = new { glsort2 = Common.ObjectToInt(_context.Request["glsort2"]), content = Common.ObjectToString(_context.Request["content"]), channel = Common.ObjectToString(_context.Request["channel"]), Data = new List<Model.API.MicroNews.Phone_ModelSubmit.Item>(), lng = Common.ObjectToString(_context.Request["lng"]), lat = Common.ObjectToString(_context.Request["lat"]) }; for (int i = 0; i < _context.Request.Files.Count; i++) { var file = _context.Request.Files[i]; var extension = Path.GetExtension(file.FileName).ToLower(); .... }
ajax 上传图片
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。