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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:04:30+00:00 2026-05-27T23:04:30+00:00

I have put together an ajax powered chat/social network with jquery, PHP – but

  • 0

I have put together an ajax powered chat/social network with jquery, PHP – but am having problems with the javascript.

I have a js file in the main page which loads the php in a div container, the js file is underneath the div. But only one function for posting a msg seems to work but the others do not.

I have tried including the js file with the dynamically loaded php at the end of the ajax load the functions work fine but am getting mutiple entries of the same message/comment.

I am pretty sure its not the PHP as it seems to work fine with no ajax involvment. Is there a way to solve this?

this is the function that works fine:

$("#newmsgsend").click(function(){

    var username = $("#loggedin").html();
    var userid = $("#loggedin").attr("uid");
    var message = $("#newmsgcontent").val();

    if(message == "" || message == "Enter Message..."){
        return false;
    }

    var datastring = 'username=' + username + '&message=' + message + '&uid=' + userid;

    //alert(datastring);

    $.ajax({
        type: "POST",
        url: "uploadmsgimage.php",
        data: datastring,

        success: function(data){
            document.newmessage.newmsgcontent.value="";

            //need to clear browse value too
            $('.msgimage').hide('slow');
            $('#addmsgimage').show('slow');
            $(".usermsg").html(data);
            $("#control").replaceWith('<input type="file" name="file"/>');
            $(".msgimage").remove();
        }
    });
});

And this is one of them that does not work:

//like btn
$(".like").click(function(){

    var postid = $(this).attr("pid");

    var datastring = 'likeid=' + postid;

    $.ajax({
        type: "POST",
        url: "addlike.php",
        data: datastring,
        success: function(data){
            $(".usermsg").html(data); 
        }
    });
});
  • 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-27T23:04:31+00:00Added an answer on May 27, 2026 at 11:04 pm

    From your post, I’m guessing that each message has a “Like” button, but you have 1 main submit button. When messages load dynamically, you have to assign the .like to each one when they come in, otherwise it will only be assigned to the existing messages.

    The problem, from what I gather (and this is a guess) would probably be fixed using live so jQuery will automatically assign the click function to all messages including dynamically loaded messages; so instead of:

    $(".like").click(function(){
    

    Try this:

    $(".like").live('click', function(){
    

    If that doesn’t solve the problem, then I’m probably not understanding what it is.

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

Sidebar

Related Questions

I have put together a small contacts management app in php for my personal
I have put together a basic order list for admin users in php for
I've put together some jQuery AJAX code using some tutorials I found on the
I have put together the following mootools script window.addEvent('domready', function() { var shouts =
I have put together a script which is very much like the flickr photostream
Greetings: I have put together a RESTful web service in .NET 3.5 that takes
I am a powershell novice. After days of searching.... I have put together a
Hello I have problem to put together animations of two separate objects to second
I have a utility that I put together that uses the .NET Framework to
I have MANY small Test Projects where I put together just enough code to

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.