用提交按钮重构ajax表单的建议?

时间:2022-10-07 20:31:17

I have this popup that holds 2 buttons to decline and accept the problem is I'm trying to style the buttons and still also trigger a JS event to close the popup ( its a modal ajax popup) Problem is I have som lack of inspiration and ideas to get the below 3 elements combined together.

我有这个弹出窗口,按住2个按钮拒绝并接受问题是我正在尝试设置按钮的样式并且仍然触发JS事件来关闭弹出窗口(它是一个模态ajax弹出窗口)问题是我缺乏灵感和som将以下3个元素组合在一起的想法。

Some rails code:

一些rails代码:

  // ACCEPT FORM
  = form_tag(friend_path, :method => 'post', :remote => true) do
    = hidden_field_tag :user_id, current_user.id
    = submit_tag 'ACCEPT'

  // DECLINE FORM
  = form_tag(friend_path, :method => 'post', :remote => true) do
    = hidden_field_tag :user_id, current_user.id
    = submit_tag 'DECLINE'
    //fbmodal.close ()

Anyone some ideas how I can have the buttons

任何人都有一些想法如何我有按钮

  • styleable ( like with twitter bootstrap )

    风格(与twitter bootstrap一样)

  • still send with ajax

    仍然发送ajax

  • trigger a JS event to close the popup?

    触发JS事件来关闭弹出窗口?

1 个解决方案

#1


1  

Styleable buttons:

时髦的按钮:

%button.btn#accept-button
  %i.icon-plus
  Accept

Your JS can then be something like:

你的JS可以是这样的:

$(document).ready(function() {
  $('#accept-button').click(function() {
    // replace this with your AJAX call
    $.get('/foo.json');
    // close the modal
    $('#your-modal-id').modal('hide');
    // and don't submit
    return false;
  });
});

#1


1  

Styleable buttons:

时髦的按钮:

%button.btn#accept-button
  %i.icon-plus
  Accept

Your JS can then be something like:

你的JS可以是这样的:

$(document).ready(function() {
  $('#accept-button').click(function() {
    // replace this with your AJAX call
    $.get('/foo.json');
    // close the modal
    $('#your-modal-id').modal('hide');
    // and don't submit
    return false;
  });
});