Last active
December 18, 2019 08:08
-
-
Save hungmi/cb057b51b3d79f524a8533d89f37bd97 to your computer and use it in GitHub Desktop.
Rails 4 with jquery-ujs: event listeners for remote link js success and error events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).on("ajax:success", ".js-remote-link", function(e, data, status, xhr) { | |
| console.log(data.message) // "SUCCESS ✓" | |
| }) | |
| // In xxxxx_controller.rb, we can write | |
| // format.js { render json: { message: "SUCCESS ✓" }, status: '200' } | |
| $(document).on("ajax:error", ".js-remote-link", function(e, xhr, status, error) { | |
| console.log(xhr.responseJSON.message) // "FAILED" | |
| console.log(status) // "error" | |
| console.log(error) // "Internal Server Error" | |
| }) | |
| // In xxxxx_controller.rb, we can write | |
| // format.js { render json: { message: "FAILED" }, status: '500' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment