zoukankan      html  css  js  c++  java
  • form表单submit按钮提交页面不跳转

     

    方案一      

    复制代码
     <html>    
      <body>    
          
      <form action="" method="post" target="nm_iframe">    
          <input type="text" id="id_input_text" name="nm_input_text" />    
          <input type="submit" id="id_submit" name="nm_submit" value="提交" />    
      </form>    
          
      <iframe id="id_iframe" name="nm_iframe" style="display:none;"></iframe>    
          
      </body>    
      </html>  
    复制代码

    方案二

    复制代码
     <html>    
      <body>    
          
      <form action="/api/user/register" method="post" id="registSubmit" >    
          <input type="text" id="id_input_text" name="nm_input_text" />    
          <input type="submit" id="id_submit" name="nm_submit" value="提交" />    
      </form>         
      </body>    
      </html>  
    复制代码
    复制代码
    $('#registSubmit').on('submit', function(){
          registPost()
    event.preventDefault() //阻止form表单默认提交
    })
    function registPost () {     
       $.ajax({
           type: "post",
           url: "/api/user/register",
           data: $('#registSubmit').serialize(),
       }).success(function(message) {
         console.log(message)
       }).fail(function(err){
         console.log(err)
       })
        /*
         或者用jquery.form.min.js提交
         $('#registSubmit').ajaxSubmit(function(message){
            console.log(message);
         })
         */
    }
    复制代码
  • 相关阅读:
    图片处理
    define 常量的定义和读取
    curl
    stream_get_contents 和file_get_content的区别
    php flock 文件锁
    字符串函数
    php 常量
    debug_backtrace()
    pathlib模块替代os.path
    Python中对 文件 的各种骚操作
  • 原文地址:https://www.cnblogs.com/zhangruisoldier/p/9166497.html
Copyright © 2011-2022 走看看