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

  • Home
  • SEARCH
  • 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 1008387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:45:49+00:00 2026-05-16T08:45:49+00:00

I have a page that sends emails to customers. It has a send all

  • 0

I have a page that sends emails to customers. It has a send all button at the bottom of the page to provide the convenience of being able to send all the emails at once. Problem is it works badly or not at all. It either isn’t redrawing the page or isn’t managing to process all the Ajax calls.

Here is the JavaScript…

function ajaxemail(element,name,email,bonus)
{
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {

            document.getElementById(element).innerHTML= xmlhttp.responseText
            //document.getElementById(element).style.display = 'none'
            //document.getElementById(element).style.display = 'block'
            //alert(xmlhttp.responseText)
        }
    }
    xmlhttp.open("POST",<?php echo "\"$_SERVER[PHP_SELF]\"";?>,true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("emailto=true&name="+name+"&email="+email+"&bonus="+bonus);
}


function sendall(info)
{
    document.getElementById('sendallmails').disabled = true
    document.getElementById('sendallmails').value = 'Sending mails...'

    length = info.length

    for( i=0; i < length; i++)
    {
        ajaxemail(info[i][0],info[i][1],info[i][2],info[i][3])

    }

}

And if it helps, here is where the array info is constructed and then the function called…

echo "<script>\nvar email_info_array = new Array()\n";

    $j = 0;

    while($row = mssql_fetch_row($rs))
    {
            echo "email_info_array[$j] = new Array('sendlink$j','$row[1]','$row[2]','$row[4]')\n";

            ++$j;
    }

    echo "</script>\n\n";


    echo "<input type=\"button\" name=\"sendallmails\" id=\"sendallmails\" value=\"Send all Mails\"  onclick=\"javascript:sendall(email_info_array)\">\n";

The failure isn’t in the page being called by function ajaxemail() because that works fine when called once or one at a time. It’s when called by the loop that it doesn’t work. It seems to do the last one or two items in the loop… or it might do some in between if I do something that forces the browser to redraw (such as resize it).

If I add an alert as a way of testing that execution of the loop is at least working it successfully runs the Ajax call on every iteration (but I have to press ok on many alerts!

I need to somehow forcibly refresh the browser DOM on every single iteration of the loop. It doesn’t matter if the page becomes less responsive (but would rather it didn’t become totally unresponsive)

I am testing in the latest Firefox (will test in other browsers once I have it working in FF)

  • 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-16T08:45:49+00:00Added an answer on May 16, 2026 at 8:45 am

    The problem here is you are using asynchronous requests with a global variable that holds the Ajax call. You are basiclaly overwritting the previous call on each iteration of the loop. You need to use a library that does not use a global variable for the Ajax call.

    Best bet is to use jQuery, Dojo, YUI, or some other JavaScript framework that supports Ajax requests.

    Other option is to use an array to hold your calls. basic idea without doing it all

    var ind = xmlhttp.push(new XMLHttpRequest()) - 1;
    

    and

    xmlhttp[ind].onreadystatechange ...
    xmlhttp[ind].open ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button on an aspx page that is supposed to send an
I have a webpage that has a button that sends a letter on the
I have made a php page that sends an email message with multiple attachments.
I have a uiwebview that sends its loaded page url to a uitableview to
I currently have a web form aspx page that calls RegisterClientScriptBlock. This sends down
I have a page that has fields dynamically loaded via JQuery. It allows a
I have a form on a page that sends data to php file via
I have a simple jsp form that the customer uses to send us emails.
I have a web page that sends email to multiple users (online distribution list).
I have a need for a simple html + javascript page that must send

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.