diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-04-19 23:37:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-19 23:37:01 -0400 |
commit | 3812ef8b664888a5ea728bc2a572074c5d9e546c (patch) | |
tree | ce9f527a65b79f32d19c5b96fd0ea85f31278b82 /guides | |
parent | 7a9098fa15e23c549b77bde4d4c534d68c6cd358 (diff) | |
parent | e3fcd96dc4b3e51e9b1260a85fe477c2a8901a75 (diff) | |
download | rails-3812ef8b664888a5ea728bc2a572074c5d9e546c.tar.gz rails-3812ef8b664888a5ea728bc2a572074c5d9e546c.tar.bz2 rails-3812ef8b664888a5ea728bc2a572074c5d9e546c.zip |
Merge pull request #32574 from DmytroVasin/rails-ujs-stoppable-events
Rails-ujs: Info about stoppable events
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/working_with_javascript_in_rails.md | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/guides/source/working_with_javascript_in_rails.md b/guides/source/working_with_javascript_in_rails.md index b9ea4ad47a..a922bdc16b 100644 --- a/guides/source/working_with_javascript_in_rails.md +++ b/guides/source/working_with_javascript_in_rails.md @@ -382,10 +382,9 @@ have been bundled into `event.detail`. For information about the previously used `jquery-ujs` in Rails 5 and earlier, read the [`jquery-ujs` wiki](https://github.com/rails/jquery-ujs/wiki/ajax). ### Stoppable events - -If you stop `ajax:before` or `ajax:beforeSend` by returning false from the -handler method, the Ajax request will never take place. The `ajax:before` event -can manipulate form data before serialization and the +You can stop execution of the Ajax request by running `event.preventDefault()` +from the handlers methods `ajax:before` or `ajax:beforeSend`. +The `ajax:before` event can manipulate form data before serialization and the `ajax:beforeSend` event is useful for adding custom request headers. If you stop the `ajax:aborted:file` event, the default behavior of allowing the @@ -393,6 +392,9 @@ browser to submit the form via normal means (i.e. non-Ajax submission) will be canceled and the form will not be submitted at all. This is useful for implementing your own Ajax file upload workaround. +Note, you should use `return false` to prevent event for `jquery-ujs` and +`e.preventDefault()` for `rails-ujs` + Server-Side Concerns -------------------- |