zoukankan      html  css  js  c++  java
  • asp.net mvc表单异步提交

    html代码:

    @using (Html.BeginForm("xx", "xx", FormMethod.Post, new { enctype = "multipart/form-data", id = "form1", @class = "form-horizontal", role = "form" }))
    {

    <div>
    @Html.DropDownList("cate", ViewData["cate"] as List<SelectListItem>, new { @class = "form-control", onchange = "SelectChange(this)", id = "select1" })
    </div>

    <div>

    <input type="file" id='picture'  accept='image/png,image/jpeg'>

    </div>

    <div>

    <button type="button" class="btn1">提交</button>

    </div>

    }

    js代码:

    $(".btn1").onclick(function(){

     var formData = new FormData();

    var cat=$("#select1").val();

    formData.append("cate", cat);

    formData.append("img",document.getElementById('picture').files[0]);

    //var xhr = new XMLHttpRequest();
    //xhr.open("post", '@Url.Action("xx", "xx")');
    //xhr.addEventListener("load", uploadComplete, false);

    ////formData.delete(imgID);
    //xhr.send(formData);
    //return false;

    $.ajax({
    url: $("#form1").attr("action"),
    type: $("#form1").attr("method"),
    cache: false,
    data: formData,
    processData: false,
    contentType: false,
    success: function (result) {
    }
    });

    })

    function uploadComplete(evt) {

    var d = evt.target.responseText.toString();
    var data = JSON.parse(d);

    }

    Control代码:

    var ca = Request.Params["cate"];

    //HttpFileCollectionBase files = Request.Files;

    HttpPostedFileBase fileimg = Request.Files[0];

  • 相关阅读:
    SHUOJ 1858 分裂的寄生兽
    POJ3057 Evacuation 解题报告
    POJ1149 PIGS 解题报告
    android与javaee通信:登录界面超级简化版
    如何实现服务器与mysql的远程通信?
    关于安卓和服务器通信的一点注意事项
    android中SQLite的基本操作
    jude的一些基本用法
    小项目难点分析
    小项目设想
  • 原文地址:https://www.cnblogs.com/ping2015/p/6122616.html
Copyright © 2011-2022 走看看