【问题标题】:How to submit bootstrap form from a modal如何从模态提交引导表单
【发布时间】:2014-11-25 18:03:24
【问题描述】:

我在引导模式的正文中有以下形式:

    <form id="contact" class="contact" name="contact">

<fieldset>

<!-- Form Name -->
<legend>Free Contact</legend>

<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="To">To</label>
  <div class="controls">
    <input id="To" name="To" placeholder="placeholder" class="input-xlarge" required="" type="text">

  </div>
</div>

<!-- Textarea -->
<div class="control-group">
  <label class="control-label" for="Message">Message</label>
  <div class="controls">                     
    <textarea id="Message" name="Message"></textarea>
  </div>
</div>

 <!--Button (Double)--> 
<div class="control-group">
  <label class="control-label" for="Send"></label>
  <div class="controls">
    <button id="Send" name="Send" class="btn btn-success">Send</button>
    <button id="Cancel" name="Cancel" class="btn btn-danger">Cancel</button>
  </div>
</div>

</fieldset>
</form>

<script>

 $("input#Send").click(function(e){


  e.preventDefault();

    $.ajax({
        type: "POST",
        url: "Update/contact", //process to mail
        data: $('form.contact').serialize(),
        success: function(msg){
                    console.log($('form.contact').serialize);

        },
        error: function(){
            alert("failure");
        }
    });
});




</script>

表单正在提交,但未提交到正确的 codeigniter 控制器和函数。它似乎从模式所在的codeigniter视图中获取URL并附加序列化的表单值,忽略我的jquery post请求。我做错了什么?

【问题讨论】:

    标签: javascript php jquery twitter-bootstrap codeigniter


    【解决方案1】:

    尝试改变你的 ajax

    $("#Send").click(function(e){
      e.preventDefault();
    
        $.ajax({
            type: "POST",
            dataType: "html"
            url: "Update/contact", //process to mail
            data: $('form.contact').serialize(),
            success: function(data){
                        console.log($('form.contact').serialize();
    
            },
            error: function(){
                alert("failure");
            }
        });
    });
    

    您忘记了序列化中的(。

    【讨论】:

      【解决方案2】:

      您的点击事件需要像这样添加到 document.ready 中:

      $(document).ready(function () {
           $("input#Send").click(function(e){
      
      
                e.preventDefault();
      
                $.ajax({
                     type: "POST",
                     url: "Update/contact", //process to mail
                     data: $('form.contact').serialize(),
                     success: function(msg){
                         console.log($('form.contact').serialize);
      
                     },
                     error: function(){
                     alert("failure");
                     }
                 });
            });
      
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-03
        • 2014-07-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多