Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8061905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:29:34+00:00 2026-06-05T10:29:34+00:00

I’m trying to write some javascript inside :javascript closure in haml template. It should

  • 0

I’m trying to write some javascript inside :javascript closure in haml template. It should show/hide divs with controls according a status which it gets over ajax call. I can’t get that code running right way. I don’t have a clue why. Ajax handlers success and complete aren’t called. Firebug shows successful ajax request and no errors in the console. I think “self” in Thin.ajax may be broken some way.

function Thin() {
  this.ajax = function() {
    $.ajax({ url: "#{check_if_running_user_case_path(@user_case)}", success: this.on_success, error: this.on_error, dataType: "json", complete: this.poll, timeout: 30000 });
  }

  this.poll = function() {
    alert("poll");
    setTimeout(this.ajax, 2000);
  };

  this.manage_divs = function(st) {
    if (st != this.running) {
      if (st == "running") {
        this.hide_div_arr_show_div([this.start_div, this.starting_div, this.stopping_div], this.stop_div);
      } else if (st == "starting"){
        this.hide_div_arr_show_div([this.start_div, this.stop_div, this.stopping_div], this.starting_div);
      } else if (st == "stopping"){
        this.hide_div_arr_show_div([this.start_div, this.stop_div, this.starting_div], this.stopping_div);
      } else {
        this.hide_div_arr_show_div([this.stopping_div, this.stop_div, this.starting_div], this.start_div);
      }
      this.running = st;
    }
  };

  this.setup  = function(start_div, starting_div, stop_div, stopping_div) {
    this.start_div    = start_div;
    this.starting_div = starting_div;
    this.stop_div     = stop_div;
    this.stopping_div = stopping_div;
    // set as stopped
    this.running = "12345";
    this.poll();
  };

  this.on_error   = function(jqXHR, textStatus, errorThrown){
    alert(["Thin polling error", textStatus]);
  };

  this.on_success = function(data, textStatus, jqXHR) {
    alert("success!");
    var st = data.user_case;
    this.manage_divs(st);
  };

  this.hide_div_arr_show_div  = function(div_arr, div){
    for(var i = 0; i < div_arr.length; i++)
        div_arr[i].hide();
    div.show();
  };
};

var thin = new Thin();
thin.setup($("#user_case_stopped"), $("#user_case_starting"), $("#user_case_running"), $("#user_case_stopping"));
thin.manage_divs("#{@running}"); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:29:36+00:00Added an answer on June 5, 2026 at 10:29 am

    Inside jQuery’s Ajax method this will refer to the global scope. Trying reference your parent object explicitly to make sure you are using the correct scope (your object):

    function Thin() {
        var that = this;
    
        that.ajax = function() {
                      $.ajax({ url: "#{check_if_running_user_case_path(@user_case)}",
                            success: that.on_success, 
                            error: that.on_error, 
                            dataType: "json", 
                            complete: that.poll, 
                            timeout: 30000 });
                    }
    
        ...
    

    Edit: Just for reference, this is a nice article on scoping this in Javascript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.