4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

coffeescript で、formのajax送信

Last updated at Posted at 2012-12-11
xxxx.coffee.js
  init_like_button: ->
    forms = $(".new_article_user")
    forms.submit (ev,f) =>
      ev.preventDefault()
      form = $(ev.target)
      num = form.parent().parent().find($(".num"))[0].textContent
      $.post form.attr("action"),form.serialize()
        ,(data) =>
		      if form.find(".submit_button").length == 0
		        form.find(".no_submit_button")[0].className = "submit_button"
		        form.parent().parent().find($(".num"))[0].textContent = parseInt(num)-1
		      else
		        form.find(".submit_button")[0].className = "no_submit_button"
		        form.parent().parent().find($(".num"))[0].textContent = parseInt(num)+1

ある一定の条件を確認してから、送信したい場合。
例:特定のinput form にカーソルがある場合で場合分け

xxxx.coffee.js
  init_submit_form: =>
    form = $("#spot_create_form")
    form.bind "submit",(ev) =>
      now_focus = $(":focus").attr("id")
      if now_focus is "search_location"
        #特定の処理
        return false
      else
        return true
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?