zoukankan      html  css  js  c++  java
  • 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 = 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();
                   ....
                }
  • 相关阅读:
    java之类的封装
    java飞机大战之子弹的自动生成
    java之线程飞机大战制作
    java线程游戏之背景图片的移动
    mysql的安装以及简单的命令符
    java之控制多幅图片
    java之线程
    JAVA之数组队列
    java之链表
    python之数据库的操作(课前准备)
  • 原文地址:https://www.cnblogs.com/OleRookie/p/6023348.html
Copyright © 2011-2022 走看看