jquery通過submit()和serialize()提交表單,jqueryserialize

來源:互聯網
上載者:User

jquery通過submit()和serialize()提交表單,jqueryserialize

<script type="text/javascript">    $(function() {        $('#form1').submit(function() { //當提交表單時,會發生 submit 事件。            //此處可做表單驗證            //... ...            var postData = $("#form1").serialize();//序列化表單,後台可正常通過post方法擷取資料            $.ajax({                type: "POST",                url: "/member/member/post_member",                data: postData,                success: function(msg) {                    if (msg == 0) {                        alert('操作成功');                        window.location.href = '/member/member';                    } else {                        alert(msg);                    }                }            });        });    });</script><div>    <form id="form1" onsubmit="return false;"><!--表單內容部分-->        <input type="reset" value="重設" />        <input type="submit" value="提交" />    </form></div>


jquery ajax 提交表單,serialize()序列化表單資料,但其對type=file的input也就是上傳不支援,怎辦?

圖片上傳可以提前進行,先上傳再提交就不會有這種問題!
如果非要一起提交的話,那可以把file單獨加入到提交序列中
$("form").serialize()+"&fileInput="+$("input[name='fileInputName']").val();這樣也是可以的

 
ajax(或者jquery)怎提交整個form表單

於是我想當修改成功的時候將資訊返回到頁面,想到ajax但是 我提交的是整個form表單的值 這個表單中有很多表單域的!就像註冊一樣要提交很多資訊但是目前$.post()這種方式是不是只帶一個參數。就算可待多個參數,那麼我是不是要在,{"":,"":.........將所有的資訊都這麼寫在這裡面}這樣是不是有點太麻煩了------解決方案--------------------------------------------------------JScript code $.ajax({ cache: true, type: "POST", url:ajaxCallUrl, data:$('#yourformid').serialize(),// 你的formid async: false, error: function(request) { alert("Connection error"); }, success: function(data) { $("#commonLayout_appcreshi").parent().html(data); } });------解決方案--------------------------------------------------------var options ={url:'xxxx.action',type:'post',data:null,success:function(data){if(data.statusCode=="OK") {}else{}}};var form =$("form[name=form1]");//form1:表單ID 在表單介面只用這一個表單IDform.ajaxSubmit(options);------解決方案--------------------------------------------------------jQuery ajax - serialize() 方法定義和用法serialize() 方法通過序列化表單值,建立 URL 編碼文本字串。您可以選擇一個或多個表單元素(比如 input 及/或 文字框),或者 form 元素本身。序列化的值可在產生 AJAX 請求時用於 URL 查詢字串中。JScript code <form> <div><input type="text" name="a" value="1" id="a" /></div> <div><input type="text" name="b" value="2" id="b" /></div> <div><input type="hidden" name="c" value="3" id="c" /></div> ......餘下全文>>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.