I have the functions mentioned below and it's way too slow. I want to replace it with a better looping system (for or foreach doesn't matter). Please just send me the code, I'm a beginner and won't never learn it.

To be more specific, It shows every result 1 by 1 every x millisecond. I want all of the results to come up at the same time.

I tried to replace it with foreach but couldn't fix it.

 function doItByProduct(id)
        {
            var max;
            <?php
                foreach( $serverData as $server => $x )
                    echo 'if( document.getElementById("server").value == "'.ucfirst($server).'" ) max = '.$x[0].';';
            ?>
            if( id < max )
            {
                xmlHttp = GetXmlHttpObject();
                if( xmlHttp == null )
                {
                    alert( "Browser does not support HTTP Request" );
                    return;
                }
                url = "getValue.php?id="+id+"&product="+document.getElementById("product").value+"&quality="+document.getElementById("quality").value+"&server="+document.getElementById("server").value;
                xmlHttp.onreadystatechange = stateChanged1;
                xmlHttp.open("GET",url,true);
                xmlHttp.send(null);
                idd += 1;
            }
            else
            {
                alert("Done");
            }
        }
function stateChanged1()
        {
            if( xmlHttp.readyState == 4 || xmlHttp.readyState == "complete" )
            {
                if( xmlHttp.responseText.search("<title>") != -1 )
                {
                    idd -= 1;
                }
                else
                {
                    document.getElementById("result").innerHTML += xmlHttp.responseText.replace('<script src="http://vvs.ir/js/ad.js"></'+'script>', '');
                }
                doItByProduct(idd);
            }
        }

0 Answers