LoginSignup
9
9

More than 5 years have passed since last update.

changeで発火するajax通信の開始時にloadingアイコンを表示して、終了時に消す

Last updated at Posted at 2014-12-11
cagegory_select_box.js.coffee
jQuery ($) ->
  showAjaxErrorMessage = ->
    alert('error message')

  $(document).delegate('.book_category_id','change', ->
    $('.book_category_id').val($(this).val())
    $('.category_select_box').submit()
    $.ajax
      beforeSend: ->
#それっぽいcssを用意しておいて、アイコンにクラスを追加する
        icon = $('.category_select_box').find('.static-icon')
        icon.addClass('loading-spin')
      success: ->
#アイコンからクラスを取り除く
        icon = $('.category_select_box').find('.static-icon')
        icon.removeClass('loading-spin')
      error: -> showAjaxErrorMessage
    )

ajaxのevent一覧はここで確認出来る
http://api.jquery.com/Ajax_Events/

9
9
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
9
9