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

  • Home
  • SEARCH
  • 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 9210937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:11:12+00:00 2026-06-18T01:11:12+00:00

I made chat system in my web application. It’s basic chat with input field

  • 0

I made chat system in my web application.
It’s basic chat with input field with messages.

I only wrapped messages_section then I’m using setInterval to load it partially and every 1 sec.
However, I found weird behaivor here.

When I’m typing something into input field, typed words get entered somehow when every time setInterval is loaded.

Now it seems that this is only affecting to browsing with FireFox:(

I was supposing setInterval wouldn’t affect to input field unless input field is set within

These are my codes. I want to know why and how to fix

jQuery

<script type="text/javascript">
//<![CDATA[
        jQuery(document).ready(function () {
            refreshPartial();
            setInterval(refreshPartial, 1000)
        });

        function refreshPartial() {
          $.ajax({
            url: "/communities/setinterval_part?page=",
            type: "GET",
            dataType: "script",
          });
        }
//]]>
</script>

HTML

  <form accept-charset="UTF-8" action="/communities/new_comments" class="new_comment" data-remote="true" id="new_comment" method="post">
      <input class="chat" id="input" name="comment[body]" type="text" />  
      <button type="submit" class="btn">submit</button>
  <form>

  <span id="messages_section">
       here comes messages!
  </span>

setinterval_part.js.erb

$('#messages_section').html("<%= j(render(:partial => 'communities/comment')) %>");
<% if @post %>$('#body_input').val('');<% end %>

communities_controller.rb

def setinterval_part
        @comments = @community.comment_threads.order("updated_at DESC").page(params[:page]).per(@number_of_comments_to_display)
        @comment = @community.comment_threads.build

    respond_to do |format|
        format.js 
    end

end
  • 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-18T01:11:13+00:00Added an answer on June 18, 2026 at 1:11 am

    First of all I recommend you do not use setInterval in this case. What if your server will take more than 1 second to answer to client? I think that you can run refreshPartial() function right from your setinterval_part.js.erb.

    So you need to make this changes to JS-part in the view:

    jQuery(document).ready(function () {
      refreshPartial();
    });
    
    function refreshPartial() {
      $.ajax({
        url: "/communities/setinterval_part?page=",
        type: "GET",
        dataType: "script",
      });
    }
    

    And this to setinterval_part.js.erb:

    $('#messages_section').html("<%= j(render(:partial => 'communities/comment')) %>");
    <% if @post %>$('#body_input').val('');<% end %>
    <% timeout_ms = 1000 %>
    <% # some code that can determine current load of your server and increase timeout_ms %>
    setTimeout(refreshPartial, <%= timeout_ms %>);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made simple web chat, bubles ( messages) above one text field (input message)
I am using the XMPP Connection(using smack) for chat in android application.I have made
I have made simply chat box application using (Ajax/jQuery, MySQL, PHP). Here is my
I've made a chat system , which works with AJAX requests. Only after a
I made a simple chat application that connects the server and client using the
I've made a fairly basic AJAX chat with PHP & MySQL. The chat messages
I have made a simple chat application which uses long-polling approach using jquery, function
I have made a simple chat application in PHP/Ajax/MySQL. I am regularly calling these
I've made a chat application for a website. Everything is working fine, however, I
I made a little chat applet using multicast. It works fine between computers on

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.