I
I
IvanN7772014-11-05 14:20:11
CoffeeScript
IvanN777, 2014-11-05 14:20:11

All javascripts were cloned, some kind of darkness went on (what did I do wrong?

I wanted to load ajax block.
This is where my nightmares started.

$ ->
  frame_d=$('div#frame_d.load')
  $("document").ready ->
    $.ajax
      type: "GET",
      url: frame_d.attr("src")
      dataType: "html"
      error: (jqXHR, textStatus, errorThrown) ->
        $('body').append "AJAX Error: #{textStatus}"
      success: (data, textStatus, jqXHR) ->
        frame_d.html(data)
        frame_d.removeClass("load")

I insert the coffeescript code
. I expect that my block will load when loading.
And it is loaded, but then loaded again and again.
I wanted to make a crutch frame_d.removeClass("load"), kill the selector in the code so that it would not load a hundred times.
But apparently he manages to dive 4 times in a row, and then stops.
As a result, when I click send request, 4 requests are sent.
When I want to delete something, it asks me about it 4 times.
In general, it seems to me that turbolinks and coffeescript are somehow having fun.
What to do?
Perhaps my crooked hands are to blame, but something needs to be done.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
eyeless_watcher, 2014-11-06
@eyeless_watcher

And if frame_d.removeClass is done before frame_d.html?

I
IvanN777, 2014-11-06
@IvanN777

my fail, sorry.
Although it says
5.2 Page Change Events
When writing CoffeeScript, you'll often want to do some sort of processing upon page load. With jQuery, you'd write something like this:
$(document).ready ->
alert "page has loaded!"
However, because Turbolinks overrides the normal page loading process, the event that this relies on will not be fired. If you have code that looks like this, you must change your code to do this instead:
$(document).on "page:change", ->
alert "page has loaded!"
What is better to enjoy another event. I just loaded the layout every time. In the end it's such a mess.
render layout: false set and everything is cool
My fake

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question