Léo Rocha
Léo Rocha

Reputation: 324

Rails.ajax call returning false (rails-ujs)

I'm trying using ajax with rails-ujs but my call doesn't doing nothing. The application use the rails 5.1 and have the rails-ujs require in application.js

When i test the code in a browser console, it is return false.

Bellow is the code:

  Rails.ajax({
    url: "/notifications.json",
    type: "GET",
    success: function(data) {
      console.log(data)
    }
  })

Upvotes: 2

Views: 467

Answers (1)

Léo Rocha
Léo Rocha

Reputation: 324

To makes the ajax call work with rails-ujs(without jQuery) i don't found any documentation at moment and hope this code bellow helpes.

Rails.ajax({
  dataType: 'script',
  url: "/notifications.json",
  type: "GET",
  beforeSend: function() {
    return true
  },
  success: function(data) {
    console.log('Ajax fine!')
  }
})

Upvotes: 1

Related Questions