【问题标题】:Submit form with jquery plug-ins使用 jquery 插件提交表单
【发布时间】:2012-08-12 00:23:58
【问题描述】:

我正在尝试使用 jquery 提交表单。我正在使用引导模式窗口。这是js fiddle。我错过了什么吗?非常感谢

更新:我正在尝试使用 ajax 提交表单。 我也尝试过,但没有运气。

$('#comment_form').on('submit', function(){

  $.post("/yourReceivingPage", $(this).serialize(), function(){

  // Hide the modal
    $("#my-modal").modal('hide');

  });

  // Stop the normal form submission
  return false;
});

【问题讨论】:

  • 您所指的php页面的名称是什么? /yourReceivingPage ?你从萤火虫那里得到任何其他错误吗?您的页面上是否还有其他框架,例如原型?
  • 你能告诉我你发送什么到.php文件当你点击post时生成了什么字符串?尝试使用alert() 来解决问题,.serialize() 之后可能会出现问题
  • 我想我已经找到了你的答案,请看这里:stackoverflow.com/questions/920294/jquery-serialize-and-post

标签: jquery twitter-bootstrap


【解决方案1】:

您引用了错误的元素,我有一个适合您的示例,请检查并告诉我它是否适合您:

$(document).ready(function() {
    $('#comment-form-submit').click(function() {
        $('#comment_form').submit();
        alert('Handler for .submit() called.');
        return false;
    });
});​

jsFiddle Working Demo

对于 AJAX 解决方案,您需要参考熟悉且已经讨论过的问题:

jquery serialize and $.post

已编辑:参考您关于如何提取可点击链接的 ID 的问题,此代码将为您完成:

 $(document).ready(function() {
   $(".comments.no").mouseover(function() {
     myDivsId = this.id;  // as you mouse over on the link it will be stored in Global Var and then transferred anywhere you wish.
   });
     $('#comment-form-submit').click(function() {
       $('#comment_form').submit();
       alert('Handler for .submit() called + div\'s ID = ' + myDivsId);
       return false;
   });

});​

jsFiddle live demo

【讨论】:

【解决方案2】:

您需要为评论表单提交按钮添加点击事件。

$(document).on('click','#comment-form-submit', function() {
    $('#comment_form').submit(function() {
       alert('Handler for .submit() called.');
       return false;
    });​
});

【讨论】:

    【解决方案3】:

    您正在寻找 submit(). 您在示例中所做的是创建一个将在提交表单时运行的函数。此外,您没有为点击提交表单设置处理程序。

    // This creates submit handler for the form
    $('#comment_form').submit(function() {
        alert('Handler for .submit() called.');
        return false;
    });​
    
    // This creates the on click handler for the submit button
    $('#comment-form-submit').on('click', function() {
        // This actually submits the form
        $('#comment_form').submit();
    });
    

    【讨论】:

      猜你喜欢
      • 2017-11-26
      • 1970-01-01
      • 1970-01-01
      • 2012-04-04
      • 2011-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多