Skip to content

Instantly share code, notes, and snippets.

@hungmi
Last active December 18, 2019 08:08
Show Gist options
  • Save hungmi/cb057b51b3d79f524a8533d89f37bd97 to your computer and use it in GitHub Desktop.
Save hungmi/cb057b51b3d79f524a8533d89f37bd97 to your computer and use it in GitHub Desktop.

Revisions

  1. hungmi revised this gist Dec 18, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions demo.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    //// For Rails projects with rails-ujs [Check official guide](https://guides.rubyonrails.org/working_with_javascript_in_rails.html#rails-ujs-event-handlers)
    //// For Rails projects with rails-ujs Check official guide: https://guides.rubyonrails.org/working_with_javascript_in_rails.html#rails-ujs-event-handlers
    // In xxx.html.erb, we can write
    // <%= link_to 'xxx', url, remote: true, data: { type: :json, disalbe_with: "...", confirm: "ok?" }, class: 'js-remote-link' %>

    @@ -28,7 +28,7 @@ $(document).on("ajax:error", ".js-remote-link", function(e) {

    ------------------------------

    //// For older Rails projects with jquery-ujs [Git repository](https://github.com/rails/jquery-ujs)
    //// For older Rails projects with jquery-ujs https://github.com/rails/jquery-ujs
    //// All events https://github.com/rails/jquery-ujs/wiki/ajax

    $(document).on("ajax:success", ".js-remote-link", function(e, data, status, xhr) {
  2. hungmi revised this gist Dec 16, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions demo.js
    Original file line number Diff line number Diff line change
    @@ -18,13 +18,13 @@ $(document).on("ajax:error", ".js-remote-link", function(e) {
    var data = event.detail[0]
    var status = event.detail[1]
    var xhr = event.detail[2]
    console.log(data) // {message: "FAILED"}
    console.log(data) // {message: "FAILED &cross;"}
    console.log(status) // Internal Server Error
    console.log(xhr)
    console.log(data.message) // "FAILED"
    console.log(data.message) // "FAILED &cross;"
    })
    // In xxxxx_controller.rb, we can write
    // format.json { render json: { message: "FAILED" }, status: '500' }
    // format.json { render json: { message: "FAILED &cross;" }, status: '500' }

    ------------------------------

  3. hungmi revised this gist Dec 16, 2019. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions demo.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    // For Rails projects with rails-ujs [Check official guide](https://guides.rubyonrails.org/working_with_javascript_in_rails.html#rails-ujs-event-handlers)
    //// For Rails projects with rails-ujs [Check official guide](https://guides.rubyonrails.org/working_with_javascript_in_rails.html#rails-ujs-event-handlers)
    // In xxx.html.erb, we can write
    // <%= link_to 'xxx', url, remote: true, data: { type: :json, disalbe_with: "...", confirm: "ok?" }, class: 'js-remote-link' %>

    $(document).on("ajax:success", ".js-remote-link", function(e) {
    var data = event.detail[0]
    var status = event.detail[1]
    @@ -27,8 +28,9 @@ $(document).on("ajax:error", ".js-remote-link", function(e) {

    ------------------------------

    // For older Rails projects with jquery-ujs [Git repository](https://github.com/rails/jquery-ujs)
    // All events https://github.com/rails/jquery-ujs/wiki/ajax
    //// For older Rails projects with jquery-ujs [Git repository](https://github.com/rails/jquery-ujs)
    //// All events https://github.com/rails/jquery-ujs/wiki/ajax

    $(document).on("ajax:success", ".js-remote-link", function(e, data, status, xhr) {
    console.log(data.message) // "SUCCESS &check;"
    })
  4. hungmi revised this gist Dec 16, 2019. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions demo.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # For Rails projects with rails-ujs [Check official guide](https://guides.rubyonrails.org/working_with_javascript_in_rails.html#rails-ujs-event-handlers)
    // For Rails projects with rails-ujs [Check official guide](https://guides.rubyonrails.org/working_with_javascript_in_rails.html#rails-ujs-event-handlers)
    // In xxx.html.erb, we can write
    // <%= link_to 'xxx', url, remote: true, data: { type: :json, disalbe_with: "...", confirm: "ok?" }, class: 'js-remote-link' %>
    $(document).on("ajax:success", ".js-remote-link", function(e) {
    @@ -25,9 +25,10 @@ $(document).on("ajax:error", ".js-remote-link", function(e) {
    // In xxxxx_controller.rb, we can write
    // format.json { render json: { message: "FAILED" }, status: '500' }

    ---
    # For older Rails projects with jquery-ujs [Git repository](https://github.com/rails/jquery-ujs)
    # All events https://github.com/rails/jquery-ujs/wiki/ajax
    ------------------------------

    // For older Rails projects with jquery-ujs [Git repository](https://github.com/rails/jquery-ujs)
    // All events https://github.com/rails/jquery-ujs/wiki/ajax
    $(document).on("ajax:success", ".js-remote-link", function(e, data, status, xhr) {
    console.log(data.message) // "SUCCESS &check;"
    })
  5. hungmi revised this gist Dec 16, 2019. 1 changed file with 32 additions and 1 deletion.
    33 changes: 32 additions & 1 deletion demo.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,33 @@
    # For Rails projects with rails-ujs [Check official guide](https://guides.rubyonrails.org/working_with_javascript_in_rails.html#rails-ujs-event-handlers)
    // In xxx.html.erb, we can write
    // <%= link_to 'xxx', url, remote: true, data: { type: :json, disalbe_with: "...", confirm: "ok?" }, class: 'js-remote-link' %>
    $(document).on("ajax:success", ".js-remote-link", function(e) {
    var data = event.detail[0]
    var status = event.detail[1]
    var xhr = event.detail[2]
    console.log(data) // {message: "SUCCESS &check;"}
    console.log(status) // OK
    console.log(xhr)
    console.log(data.message) // "SUCCESS &check;"
    })
    // In xxxxx_controller.rb, we can write
    // format.json { render json: { message: "SUCCESS &check;" }, status: '200' }

    $(document).on("ajax:error", ".js-remote-link", function(e) {
    var data = event.detail[0]
    var status = event.detail[1]
    var xhr = event.detail[2]
    console.log(data) // {message: "FAILED"}
    console.log(status) // Internal Server Error
    console.log(xhr)
    console.log(data.message) // "FAILED"
    })
    // In xxxxx_controller.rb, we can write
    // format.json { render json: { message: "FAILED" }, status: '500' }

    ---
    # For older Rails projects with jquery-ujs [Git repository](https://github.com/rails/jquery-ujs)
    # All events https://github.com/rails/jquery-ujs/wiki/ajax
    $(document).on("ajax:success", ".js-remote-link", function(e, data, status, xhr) {
    console.log(data.message) // "SUCCESS &check;"
    })
    @@ -11,4 +41,5 @@ $(document).on("ajax:error", ".js-remote-link", function(e, xhr, status, error)
    console.log(error) // "Internal Server Error"
    })
    // In xxxxx_controller.rb, we can write
    // format.js { render json: { message: "FAILED" }, status: '500' }
    // format.js { render json: { message: "FAILED" }, status: '500' }

  6. hungmi revised this gist Dec 16, 2019. No changes.
  7. hungmi revised this gist Dec 2, 2019. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions demo.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,14 @@
    $(document).on("ajax:success", ".js-task-card__remote-link", function(e, data, status, xhr) {
    $(document).on("ajax:success", ".js-remote-link", function(e, data, status, xhr) {
    console.log(data.message) // "SUCCESS &check;"
    })
    // In xxxxx_controller.rb, we can write
    // format.js { render json: { message: "SUCCESS &check;" }, status: '200' }


    $(document).on("ajax:error", ".js-task-card__remote-link", function(e, xhr, status, error) {
    $(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' }
  8. hungmi revised this gist Dec 2, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions demo.js
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    $(document).on("ajax:success", ".js-task-card__remote-link", function(e, data, status, xhr) {
    console.log(data.message)
    console.log(data.message) // "SUCCESS &check;"
    })
    // In xxxxx_controller.rb, we can write
    // format.js { render json: { message: "SUCCESS &check;" }, status: '200' }


    $(document).on("ajax:error", ".js-task-card__remote-link", function(e, xhr, status, error) {
    console.log(xhr.responseJSON.message)
    console.log(xhr.responseJSON.message) // "FAILED"
    })
    // In xxxxx_controller.rb, we can write
    // format.js { render json: { message: "FAILED" }, status: '500' }
  9. hungmi revised this gist Dec 2, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions demo.js
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,11 @@ $(document).on("ajax:success", ".js-task-card__remote-link", function(e, data, s
    console.log(data.message)
    })
    // In xxxxx_controller.rb, we can write
    // format.js { render json: { message: "處理成功 &check;" }, status: '200' }
    // format.js { render json: { message: "SUCCESS &check;" }, status: '200' }


    $(document).on("ajax:error", ".js-task-card__remote-link", function(e, xhr, status, error) {
    console.log(xhr.responseJSON.message)
    })
    // In xxxxx_controller.rb, we can write
    // format.js { render json: { message: "處理失敗" }, status: '500' }
    // format.js { render json: { message: "FAILED" }, status: '500' }
  10. hungmi created this gist Dec 2, 2019.
    12 changes: 12 additions & 0 deletions demo.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    $(document).on("ajax:success", ".js-task-card__remote-link", function(e, data, status, xhr) {
    console.log(data.message)
    })
    // In xxxxx_controller.rb, we can write
    // format.js { render json: { message: "處理成功 &check;" }, status: '200' }


    $(document).on("ajax:error", ".js-task-card__remote-link", function(e, xhr, status, error) {
    console.log(xhr.responseJSON.message)
    })
    // In xxxxx_controller.rb, we can write
    // format.js { render json: { message: "處理失敗" }, status: '500' }