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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:21:36+00:00 2026-06-13T23:21:36+00:00

Sorry guys, maybe this has been asked before. But I googled around for several

  • 0

Sorry guys, maybe this has been asked before. But I googled around for several days and still cannot solve the problem. I am developing a chatting system using Google App Engine with Python. I would like the user to enter her/his message and click “Submit” button. That action will trigger an Ajax post function “addMsg()” to POST the message to class Chat (URL: “/chat”), which will add the message to datastore. There is another Ajax function “updateMsg()” which will update the message list periodically.

The code works fine for message updating, however, I am not able to post the message correctly. Can anybody help me? Thanks. Here are my codes:

chat.html:

    <p>
    <form method="" action="">
    <input type="text" name="message" size="60" /><br />
    <input type="button" value="Submit" onclick="addMsg('message')" />
    </form>
    </p>
    <div id="chatcontent"> </div>
    <script>
    function addMsg(message) {
        $.ajax({
            type: "POST",
            url: "/chat",
            data: {'message': message},
            cache: false
        });
    }
    </script>

    <script>
    $(document).ready(function() {
        function updateMsg() {
            $.ajax({
               url: "/message",
               cache: false,
               success: function(returndata){
                    $("#chatcontent").html(returndata);
               }
            });
            setTimeout(updateMsg, 4000);
        }
        updateMsg();
    });
    </script>

message.html:

    {% for chat in chatlist %}
    <p>
      {{ chat.text }} ({{ chat.user.account }}) {{chat.created|date:"D d M Y" }}
    </p>
    {% endfor %}

chat.py:

    # Called by URL "/chat"
    class Chat(webapp2.RequestHandler):
        def post(self):
            message = self.request.get('message')
            newchat = ChatMessage(user=self.session['userkey'], text=message, created=datetime.datetime.now())
    newchat.put()

    # Called by URL "/message"
    class Message(webapp2.RequestHandler):
        def get(self):
            que = db.Query(ChatMessage).order('-created')
            chatlist = que.fetch(limit=100)
            render(self, 'message.html', {'chatlist': chatlist})
            # Note: render() is a function to be imported, which is just a normal template rendering function. It works fine and is omitted here.
  • 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-13T23:21:37+00:00Added an answer on June 13, 2026 at 11:21 pm

    Chat.html

    <p>
    <input type="text" name="message" size="60" /><br />
    <input type="button" value="Submit" onclick="addMsg()" />
    </p>
    <div id="chatcontent"> </div>
    <script>
    function addMsg() {
        var message = $('input[name=message]').val();
        $.ajax({
            type: "POST",
            url: "/chat",
            data: {'message': message},
            cache: false
        });
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: Sorry Guys, This has been resolved The comment to check the inline style
Sorry guys, didn't know how to word this one. Still learning jquery and have
guys sorry for being so noob but im still starting yet with my php,
Sorry for the wall of text guys but this one requires expliaining, way too
Sorry guys,just a simple question but I cannot find exact question on google. The
Sorry guys, Ive googled and still cant get my code to work. Not exactly
I'm sorry if maybe the question it's a bit wide guys, but I've tried
Hey guys, sorry for this probably fairly simple question but I'm starting to get
Edit: Sorry guys, but I wasn't seeing this behavior when I came into work
Hey guys sorry to ask but i need help with this query please I've

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.