Home>

I'm suffering from an event that doesn't fire in asynchronous communication with the comment function

id: "new_comment" is defined in the form_for part of the comment input part of the file name.
I couldn't catch fire when I checked on the verification screen with console.log (this).

file<comments.js>
$(function () {
$('# New_comment'). On ('submit', function (e) {
   E.prevebtDefault ();
   Confirmation on console.log (this) // verification screen does not fire well
   Var formData = new FormData (this);
}))
})
file<create.json.jbuilder>
json.text @ comment.text
json.user_id @ comment.user.id
json.user_name @ comment.user.nickname
file name<show.html.haml>
.container
      -if current_user
        = form_for [@ tweet, @ comment], id: "new_comment" do | f |
          = f.text_field: text, class: 'form__message', placeholder: 'comment'
          .form__mask
          = f.submit 'Send', class: 'form__submit'
      -else
        % strong
          % p ※※※ New registration/login required to post comments ※※※
      .comments
        % h4<Comment list>
        -if @comments
          [email protected] comments.each do | comment |
            % p
              % strong
                = link_to comment.user.nickname, "/users/#{comment.user_id}"
                :
              = comment.text
  • Answer # 1

    File

      

    e.prevebtDefault ();

    It looks like

    is Typo.
    The following is correct.

    e.preventDefault ();

    Reference: https://developer.mozilla.org/en/docs/Web/API/Event/preventDefault

  • Answer # 2

    Js source contains double-byte spaces andpreventDefaultI'm curious about what is not

Related articles