zoukankan      html  css  js  c++  java
  • Ajax提交Form表单的一种方法

    待提交的表单

     <form id="updatePublicKey" enctype="multipart/form-data">
      <div class="left">
        <ul>
          <li>
            <div class="label">邮箱</div>
            <div class="ui corner labeled disabled input">
              <input type="text" disabled="disabled" value="${user.email}" placeholder="Required Field" />
            </div>
          </li>
          <li>
            <div class="label">用户名</div>
            <div class="ui corner labeled disabled input">
              <input type="text" disabled="disabled" value="${user.username}" placeholder="Required Field" />
            </div>
          </li>
          <li>
            <div class="label">
            <span>*</span>Sudo密码</div>
            <div class="ui corner labeled input">
              <input type="password" iplaceholder="" id="password" name="password" />
            </div>
            <p class="italic inputdescription">需包含字母、数字、符号,八位及以上。
            <br />Sudo密码在设备上切换到管理员用户时将使用。</p>
            <p class="red" id="sudoNo" style="display: none;">密码不符合规则</p>
          </li>
          <li>
            <div class="label">
            <span>*</span>Sudo密码确认</div>
            <div class="ui corner labeled input">
              <input type="password" placeholder="" id="passwordconfirm" name="passwordconfirm" />
            </div>
            <p class="red" id="twiceNo" style="display: none;">两次密码输入不一致</p>
          </li>
        </ul>
      </div>
      <input id="submit" type="button" class="ui teal button uploadsubmit" value="提交" style="border:0;"/>
    </form>
    

    ajax提交Form表单

    $("#submit").click(function(){
    			 var $form = $("#updatePublicKey");
    			 var formData = new FormData($form[0]);
    			 formData.append("userName", userName);//添加参数数据
                 $.ajax({
                     url: updatekey_url,
                     data:formData,
                     type: 'POST',
                     cache: false,
                     contentType: false,
                     processData: false,
                     xhr: function() {
                         myXhr = $.ajaxSettings.xhr();
                         return myXhr;
                     },
                     success: function(json) {
                    	 // 
                    	 if (json.status == 0) {
                    		 location.href = publickey_index_url;
                         } else {
                       	  	alert(json.msg);
                         }
                      
                     }
                 });
    	});
  • 相关阅读:
    Linux 分区注意事项
    wamp2.4-- 为WAMP中的mysql设置密码密码
    转multicast vs broadcast
    转 生成 HTMLTestRunner 测试报告
    Eclipse和PyDev搭建完美Python开发环境(Windows篇)
    转 深入解析浏览器的幕后工作原理
    selenium + python 怎样才能滚到页面的底部?
    Java ZIP压缩和解压缩文件(解决中文文件名乱码问题)
    Java中使用poi导入、导出Excel
    eclipse下的tomcat内存设置大小
  • 原文地址:https://www.cnblogs.com/ITer-jack/p/7145675.html
Copyright © 2011-2022 走看看