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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:51:30+00:00 2026-06-12T11:51:30+00:00

I have a script that runs continuously on my page, and it detects if

  • 0

I have a script that runs continuously on my page, and it detects if a new item has been submitted to my database, at which point it adds additional html to my page:

var count_cases = -1;

setInterval(function(){    
    $.ajax({
        type : "POST",
        url : "new_lead_alerts_process.php",
        dataType: 'json',
        cache: false,
        success : function(response){
            $.getJSON("new_lead_alerts_process.php", function(data) {
                if (count_cases != -1 && count_cases != data.count) {
                    //add new HTML element to page
                    $('#content').prepend("<div class=\"reportRow\"><div id=\"reportRowLeft\" style=\"width: 63px;\">"+dayOfMonth+"</div><div id=\"reportRowCenter\">"+timeSubmitted+"</div><div id=\"reportRowRight\" style=\"width: 126px;\"><div id=\"claimButton"+data.id+"\"><form action=\"\" method=\"post\" name=\""+data.id+"\"><input type=\"hidden\" id=\"lead_id"+data.id+"\" name=\"lead_id\" value=\""+data.id+"\" /><input type=\"hidden\" id=\"client_id"+data.id+"\" name=\"client_id\" value=\""+data.client_id+"\" /><input type=\"hidden\" id=\"user_id"+data.id+"\" name=\"user_id\" value=\"1\" /><input type=\"image\" name=\"submit\" class=\"claimButton\" onClick=\"expand('claimed"+data.id+"');collapse('claimButton"+data.id+"');\" src=\"images/claim.gif\" id=\""+data.id+"\" style=\"width: 126px; height: 29px; margin: 0; border: 0px; padding: 0; background: none;\"></form></div><img id=\"claimed"+data.id+"\" style=\"display: none;\" src=\"images/claimed.gif\" /></div><div id=\"clear\"></div></div>");
                }
            count_cases = data.count;
            });
        }
    });
},1000);

I have another script that submits an update to the database via AJAX when a user clicks a button in the newly created element. It looks like this:

//update db when lead is claimed
$(document).ready(function(){
    $(".claimButton").click(function(){
        var element = $(this);
        var Id = element.attr("id");
        var client_id = $("#client_id"+Id).val();
        var user_id = $("#user_id"+Id).val();
        var lead_id = $("#lead_id"+Id).val();
        var dataString = 'client_id='+client_id+'&user_id='+user_id+'&lead_id='+lead_id;
        
        $.ajax({
            type: "POST",
            url: "new_lead_alerts_update.php",
            data: dataString,
            cache: false
        });
    return false;});
    });

My issue, is that the second AJAX submit doesn’t appear to be working. I think this is due to the fact that the $(document).ready command only fires when the page first loads, and due to the fact that I’m updating the page content dynamically via AJAX, any new elements added to the page can’t be submitted.

I’ve tried .delegate and .live, as opposed to .ready and neither appeared to work.

Any help would be greatly appreciated.

  • 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-12T11:51:31+00:00Added an answer on June 12, 2026 at 11:51 am

    Make the functionality from document.ready into a callback, and then do that every time you append a new element to the page from ajax like this:

    $(document).ready(function(){ MakeClaim(); });
    
    function MakeClaim(){
     $(".claimButton").click(function(){
        var element = $(this);
        var Id = element.attr("id");
        var client_id = $("#client_id"+Id).val();
        var user_id = $("#user_id"+Id).val();
        var lead_id = $("#lead_id"+Id).val();
        var dataString = 'client_id='+client_id+'&user_id='+user_id+'&lead_id='+lead_id;
    
        $.ajax({
            type: "POST",
            url: "new_lead_alerts_update.php",
            data: dataString,
            cache: false
        });
     return false;});
    }
    
    success : function(response){
            $.getJSON("new_lead_alerts_process.php", function(data) {
                if (count_cases != -1 && count_cases != data.count) {
                 //that huge string
                 MakeClaim();
                }
                count_cases = data.count;
            });
    }
    

    EDIT

    try changing this:

    onClick=\"expand('claimed"+data.id+"');collapse('claimButton"+data.id+"');\"
    

    to

    onClick=\"expand('claimed"+data.id+"');collapse('claimButton"+data.id+"');return false;\"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python script that runs a program, which generates few .exe files
I have a script that runs a stored procedure in my SQL server database,
I have a PHP script that runs database queries. Now, if a query fails,
I have a script that runs CPAN::Mini::Inject actions and has an App::Cache. It works
I have a python script that runs continuously in background and print some logs
I have a python script that runs continuously. It outputs 2 lines of info
I have a script that runs every two minutes for a Tweet-getter application. In
I have a script that runs every minute at XX:00. The script loops over
I have a script that runs at evening, it writes to a log file
I have a JScript script that runs using cscript.exe . It creates a shortcut

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.