h5 form 帶有檔案的遞交 自動驗證 ajax

java_陳序猿發表於2017-06-28
<script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>

<script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_zh.js"></script>

<form   method="post" class="form-horizontal"  id="item4FormHandle"  enctype="multipart/form-data">

$().ready(function() {
    $("#item4FormHandle").validate({
        submitHandler:function(form){
            ajaxPutInto();
        }
    });
});

function ajaxPutInto(){
    var formData = new FormData(document.getElementById("item4FormHandle"));//表單id
    $.ajax({
        url: 
        type: 'POST',
        data: formData,
        async: false,
        cache: false,
        contentType: false,
        processData: false,
        success: function (result) {
            console.log(result);
            alert("遞交成功");
        }});
};


<button id="putInto"   class="btn btn-sm btn-info pull-right m-t-n-xs" type="submit"><strong>確 定 提 交</strong></button>





















相關文章