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 6999275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:31:12+00:00 2026-05-27T20:31:12+00:00

I have a problem with my very simple chat. The page is constanly refreshing

  • 0

I have a problem with my very simple chat. The page is constanly refreshing with AJAX with an timeout of 750ms. If I press or use enter to submit my ‘reaction’, the page refreshes: is there an way to remove that, so that you can instantly see what you’ve posted?

You can see the chat at my website: chat

The code:
Index.php

<!DOCTYPE HTML>
<?php include 'config.php'; ?>
<html>
<head>
<script type="text/javascript" src="jquery-1.7.1.js">
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}


</script>

    <title>JavaScript Chat</title>
    <link href="style.css" rel="stylesheet" type="text/css"/>

</head>
<body>
    <div class="container">
        <div id="chatwindow">

        </div>

        <div class="inputMessage">
            <form method="post">


    enter code here

            <hr></hr>
                <textarea name="message" rows="1" cols="55"></textarea><br/>Fill username here<br/>
                <input type="text" value="" name="username" />
                <input type="submit" value="verstuur" name="submit" onKeyPress="return submitenter(this,event)" />

            </form>
            <?php   include 'send.php'; ?>      
        </div>

        <script type="text/javascript">
          $(document).ready(function(){
            setInterval ( "get()", 750 );
          });
          function get(){
             $.ajax({
               type: 'GET',
               url: 'chat.php',
               success: function(data){
                 $("#chatwindow").html(data);
               }
             });
          }
        </script>
</div>
</body>
</html>

chat.php

<?php
    include 'config.php';
    $result = mysql_query("select * from Message");
    while($row = mysql_fetch_array($result))
    {
        echo '<p>' . $row['username'] . " : " . $row['message'] . '</p>';
    }
?>  

send.php

<?php 

if(isset($_POST['submit'])) 
    {
    if (!empty($_POST['username']))
        {
            if(!empty($_POST['message']))
            {
                $message =  mysql_real_escape_string(htmlentities($_POST['message']));
                $username =  mysql_real_escape_string(htmlentities($_POST['username']));
                $query = "INSERT INTO Message (`username`,`message`) VALUES ('".$username."','".$message."')";
                mysql_query($query);
            }
            else
            {
            echo '<script type="text/javascript">alert(\'Je kan niet niks sturen\')</script>'; 
            }
        }
    else
    {
        echo '<script type="text/javascript">alert(\'Vul een gebruikresnaam in!\')</script>';
    }
}
?>

if my question is not clear say it please.
And is there a topic/question/post about good spacing? google translated it as “indent”.
Thanks

  • 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-05-27T20:31:13+00:00Added an answer on May 27, 2026 at 8:31 pm

    Replace

    <form method="post">
    

    With

     <form onsubmit="event.preventDefault()" method="post">
    

    You may also use your callback function here like:

     <form onsubmit="event.preventDefault();return submitenter(this,event);" method="post">
    

    Working demo: http://jsfiddle.net/usmanhalalit/5RCwF/2/

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

Sidebar

Related Questions

It's a very simple problem that I have. I use XDocument to generate an
i have very simple problem. I need to create model, that represent element of
I have a very simple problem which requires a very quick and simple solution
I have a very simple problem and a solution that will work, but I'm
I have a very simple problem but cannot find a nice solution. I have
I have made a very simple AppleScript to close tabs in Safari. The problem
The problem seems very strange. I have a AJAX helper function within a same
I am new to Perl and I have a problem that's very simple but
I have a very simple problem in which I need to do something after
I have a very simple problem. I have x = [1 2 3 4

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.