Prabhakaran
Prabhakaran

Reputation: 4013

coffee script not showing ajax status message

->
    $('#new_category').bind "ajax:beforeSend", ->
        notification = 'test'
        $('#notification').html notification

The above code generates js code of

(function() {
  return $('#new_category').bind("ajax:beforeSend", function() {
    var notification;
    notification = 'test';
    return $('#notification').html(notification);
  });
});

But the element with id notification is empty it is not working.

Upvotes: 2

Views: 132

Answers (3)

Prabhakaran8737
Prabhakaran8737

Reputation: 81

Did you try with document.ready function

$(document).ready ->
    $('#new_category').on "ajaxSend", ->
        notification = 'test'
        $('#notification').html notification

I hope this helps

Upvotes: 0

sbking
sbking

Reputation: 7680

You are just creating a function expression, not actually running it anywhere. Also, I'm not sure where you got that event name? Here is the list of jQuery AJAX events, I think you want the global 'ajaxSend' event. Try this:

do ->
  $('#new_category').on 'ajaxSend', ->
    notification = 'test'
    $('#notification').html notification

Upvotes: 1

Matthew Blancarte
Matthew Blancarte

Reputation: 8301

You'll want to do a few things:

  1. Run this code when the DOM is ready
  2. Use .on() in place of .bind() if you are using jQuery 1.7+
  3. As @cuberto pointed out, you'll want to use the global ajaxSend event

So your code should look like:

$ ->
    $('#new_category').on "ajaxSend", ->
        notification = 'test'
        $('#notification').html notification

Upvotes: 1

Related Questions