码迷,mamicode.com
首页 > Web开发 > 详细

ajax 上传图片

时间:2016-11-02 17:37:17      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:pen   one   ...   class   channel   ring   i++   mic   for   

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 = 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 上传图片

标签:pen   one   ...   class   channel   ring   i++   mic   for   

原文地址:http://www.cnblogs.com/OleRookie/p/6023348.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!