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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:47:32+00:00 2026-06-14T20:47:32+00:00

I am using immediately invoked functions pattern, but this is not passing the id

  • 0

I am using immediately invoked functions pattern, but this is not passing the id

1.When the user clicks on $user, id is passed and the chat window appears

echo "<div class='boxbottom'><a href='#' onclick=chat_com_one($id);> >$user</a><br></div>";

2.Function chatcom_load_one keep checking, if there is any message from the id passed to chatcom_load_one function.

But the problem is that onclick function do passes the id but immediately invoked function did not pass the id to the post function.

Also sending the message is slow?

Please help or suggest any alternate approach, I think error is in the chat_load_one pattern.

function chat_com_one(id) {

    $('#chatcom').show('fast');
    (function chatcom_load_one(id) {
        $.post('sendchat2.php', {
            option: 'chatcom_load_one',
            tocom: id
        }, function (data) {
            $('#chatcom #commid #commidwin').html(data);
            setTimeout(chatcom_load_one(id), 1000);
        });
    }());
    $('#chatcom_send').click(function () {
        var text = document.getElementById('chatcom_text').value;
        $.post('sendchat2.php', {
            option: 'chat_com_send_one',
            text: text,
            tocom: id
        }, f
        function (data) {
            document.getElementById('chatcom_text').value = '';
        });
    });
}

send function on my server

    if($_REQUEST['option']=='chat_com_send_one'){
    $session=new $session;
    $text=mysqli_real_escape_string($db3->connection,$_POST['text']);
    $tocom=mysqli_real_escape_string($db3->connection,$_POST['tocom']);
    $sql=mysqli_query($db3->connection,"INSERT INTO chat_com(fro,tocom,mesg,time) VALUES ('$session->userid','$tocom','$text',CURRENT_TIMESTAMP)");
}
  • 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-14T20:47:34+00:00Added an answer on June 14, 2026 at 8:47 pm

    First off, I notice two problems:

    • You have a syntax error in the parameter list to $.post
    • You probably don’t want to do this: setTimeout(chatcom_load_one(id), 1000);

    Here’s an updated version of your code with these errors fixed:

    function chat_com_one(id) {
    
        $('#chatcom').show('fast');
        (function chatcom_load_one(id) {
            $.post('sendchat2.php', {
                option: 'chatcom_load_one',
                tocom: id
            }, function (data) {
                $('#chatcom #commid #commidwin').html(data);
                setTimeout(function () {
                    chatcom_load_one(id);
                }, 1000);
            });
        }());
    
        $('#chatcom_send').click(function () {
            var text = document.getElementById('chatcom_text').value;
            $.post('sendchat2.php', {
                option: 'chat_com_send_one',
                text: text,
                tocom: id
            },
            function (data) {
                document.getElementById('chatcom_text').value = '';
            });
        });
    }
    

    Also, since you’re using jQuery, you can simplify document.getElementById.... Another updated version (with some more changes to make it more readable):

    function chat_com_one(id) {
        $('#chatcom').show('fast');
    
        (function chatcom_load_one(id) {
            $.post('sendchat2.php', {
                option: 'chatcom_load_one',
                tocom: id
            }, function (data) {
                $('#commidwin').html(data);
                setTimeout(function () {
                    chatcom_load_one(id);
                }, 1000);
            });
        }(id));
    
        $('#chatcom_send').click(function () {
            var text = $('#chatcom_text').val();
            $.post('sendchat2.php', {
                option: 'chat_com_send_one',
                text: text,
                tocom: id
            },
            function (data) {
                $('#chatcom_text').val('');
            });
        });
    }
    

    These are just a few cleanups, there may be others.

    Edit:

    Added devnull69’s insight to my final updated code. Hopefully it’s useful (accept his answer if this was the problem).

    Edit: Other notes

    Why are you doing $.post in chatcom_load_one? It would make much more sense as a $.get, and the query parameters would still be sent. It’s not really a problem per se, but it’s bad style. This should probably be in a file called getchat.php or something instead of doing what I expect is looking for the text parameter.

    Also, I don’t know the implementation of sendchat2.php, but you should probably reduce the timeout. Try something like 250ms or so. That’s not going to overload the server and it’ll improve response time.

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

Sidebar

Related Questions

Using JQuery, is there a simple way to select the text immediately after a
When appending to a file using Windows batch commands, how to append immediately after
Does anyone know how to clear the immediate window using VBA? While I can
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using CI for the first time and i'm smashing my head with this seemingly
In my application I'm using LDAP authentication. But i'm also have 2 remote services
I'm trying to implement multistage animation using UIViewAnimationOptionBeginFromCurrentState to allow the user to cancel
I'm after opinions please on this attempt at MVC using Java Graphics2D. I wanted
I'll prefix this question with: No, Setting IRONPYTHONPATH is not the answer. Anyway... I
I have a Silverlight 3 tools library with a custom DataGrid user control. 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.