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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:04:25+00:00 2026-06-09T20:04:25+00:00

When someone clicks a button on my web page, this JavaScript code runs: function

  • 0

When someone clicks a button on my web page, this JavaScript code runs:

function count() {
    var xmlHttp = getXMLHttp(); // XMLHttpRequest object
    xmlHttp.open("GET", "count.php", true);
    xmlHttp.send(null);
}

Then, this PHP script gets executed: (a common)

<?php

mysql_connect("host","username","password"); 
mysql_select_db('database');
mysql_query('UPDATE table SET field = field + 1'); 

?>

The problem may vary. Lets say I click ten times, it only registers 8 or something. Sometimes it works, other times it does not.

  • 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-09T20:04:27+00:00Added an answer on June 9, 2026 at 8:04 pm

    There is always a solution…

    Quick Fix Solution @

    Make Your AJAX call synchronous. Note: This will make the Generate button seem stuck during the duration of execution and I think you don’t want that (as you are keeping all the names in JS array for faster loading… Yes i visited your link… thanks for posting it)

    function count() {
        var xmlHttp = getXMLHttp();
        var async = false;
        xmlHttp.open("GET", "count.php?" + Math.random, async);
        xmlHttp.send();
    }
    

    Better Solution

    //call submit count every 60 secs, play with it to get a interval that suits you best
    window.setTimeout("submitCount();",60000);
    var globalCounter = 0;
    function count() 
    {
        globalCounter++;
    }
    
    function submitCount(){
        if (globalCounter > 0)
        {
            var xmlHttp = getXMLHttp();
            var async = false;
            var countForPHP = globalCounter;
            globalCounter = 0;
            xmlHttp.open("GET", "count.php?r=" + Math.random + "&count=" + countForPHP, async);
            xmlHttp.send();
        }
        window.setTimeout("submitCount();",60000);
    }
    

    Change your PHP to get countForPHP from Request.QueryString and update SQL accordingly

    Note: Counts will be lost when the website is closed and that 60 sec lot is not committed to server. To take care of that you may want to call submitCount on window.onbeforeunload

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

Sidebar

Related Questions

Is this possible? When someone clicks a Facebook Like button, he/she shares the web
For example, when someone clicks on a button.
I am trying to write a simple JavaScript page timer for a web app.
I have read this link How can we stop web page view after sign-out
I am working on a web application project using Tapestry 5 framework/javascript. This application
I am creating a web page where someone can visit it. They type a
Can someone tell me what's wrong with this code? I'm trying to upload a
The cat that is on this web page is suppose to move when you
In my web page there is link button and on that link button i
I'd like a link where if someone clicks a mailto link they are also

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.