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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:42:03+00:00 2026-05-16T04:42:03+00:00

I’ve recently started exploring using AJAX for a small project, and I’ve had reasonable

  • 0

I’ve recently started exploring using AJAX for a small project, and I’ve had reasonable success though it’s not as smooth as I would like.

The Basic setup is that an applications named ProphetX which interfaces with Excel to show stock market prices. Prices are updated as they change in Excel. Using VBA I save the data from the spreadsheet into an SQL08 DB every time a price updates. This could sometimes be a few times per second.

Using PHP on an Apache server I connect to the SQL DB and load the data into tables, and a javascript function to keep updating the information once every second. I’ve noticed however that at times the page will simply hang if you already have it up, or load a blank screen if you pull it up, particularly when data is being updated rapidly. So to the meat of my question: Is there something in my code which could be causing this hiccup? I doubt it is congesting the network or server resources as I’ve been monitoring them and they seem low.

Also I used WireShark to monitor network traffic, and when I load up the page and it shows blank in the browser, I can see the HTML being sent from the server to my machine.

Any help / coding style criticism is much appreciated, source code below.

Index.php:

<html>
<head>
<script type="text/javascript" src="update.js"></script>
</head>
<body onLoad = update()>
<font size = +2>
<?php
echo "
<div id = 'marketData'></div>
";
?>
</font>
</body></html>

Update.js:

function update()
{
    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("marketData").innerHTML=xmlhttp.responseText;
        }
     }
     //URL needs a var to be passed via get for code to function in IE, thus Math.Random().
//I am also confused by this requirement.
    xmlhttp.open("GET","update.php?i="+ Math.random(),true);
    xmlhttp.send();
    var t = setTimeout("update()", 3000);
}

Update.php:

<?php
//connect to database
error_reporting(0);
    sqlsrv_configure("WarningsReturnAsErrors", 1);
    $server = "myServer";
    $db = "myDB";
    $connectionInfo = array("Database"=>"$db, "UID"=>"user", "PWD"=>"pass");
    $conn = sqlsrv_connect($server, $connectionInfo);

    if($conn)
    {
        echo "<font size =-1 color=green>Connection Established<br></font>";
    }
    else
    {
        echo"Connection not established:<br>";
        print_r(sqlsrv_errors());
    }   

    //Func calls sqlsrv_query($conn, [$symbol],[$DatabaseName])
    $stmt = sqlsrv_query($conn,query(array('sym1','sym2','sym3'), "electronic") );
    errorCheck($stmt);
    printTables("Electronic Commodity Prices", $stmt);

    $stmt = sqlsrv_query($conn,query(array('sym1','sym2','sym3'), "floor") );
    errorCheck($stmt);
    printTables("Floor Commodity Prices", $stmt);

    $stmt = sqlsrv_query($conn,query(array('sym1','sym2','sym3',... ,sym19), "natgas") );
    errorCheck($stmt);
    printTables("Natural Gas Commodity Prices", $stmt);

    sqlsrv_free_stmt($stmt);
    sqlsrv_close( $conn);

    //This function prints out the tables
    function printTables($tableName, $stmt)
    {
        echo
        "
        $tableName<hr>
        <table cellspacing ='5' cellpadding = '5'>
        <tr>
            <th>Symbol</th>
            <th>Product</th>
            <th>Last Price</th>
            <th>Change</th>
            <th>High Price</th>
            <th>Low Price</th>
            <th>Previous Price</th>
            <th>Trade Time</th>
        </tr>
        ";
        while($row=sqlsrv_fetch_array($stmt))
        {
        echo 
        "
        <tr>
            <td>$row[symbol]</td>
            <td><font size =+3 color = blue>$row[description]</font></td>
            <td>$row[last]</td>
            <td><font size =+5> $row[change]</font></td>
            <td>$row[highPrice]</td>
            <td>$row[lowPrice]</td>
            <td>$row[previousprice]</td>
            <td>" .  date("j M g:i",strtotime($row['tradetime']))  . "</td>
        </tr>
        ";
        }
        echo"</table><hr>";
    }
    function query($symbols, $db)
    {
    $count = count($symbols);
        $stmt = 
        "
                select distinct id,symbol,description,last,change,highPrice,lowPrice,previousprice,tradetime from $db
                where ";
                for($i = 0; $i< $count; $i++)
                {
                    $stmt .= "id in (select MAX(id)from $db where symbol ='$symbols[$i]') ";
                    if($i != $count-1)
                    {
                        $stmt.= "or ";
                    }
                }
                $stmt .= "order by description asc";
                // id in (select MAX(id)from $db where symbol ='$symbols[0]')
                // or id in (select MAX(id)from $db where symbol ='$symbols[1]')
                // or id in (select MAX(id)from $db where symbol ='$symbols[2]') 
                    // order by description asc
        return $stmt;
    }
    function errorCheck($stmt)
    {
        if( $stmt=== false )
        {
            echo "Error in statement preparation/execution.\n";
            die( print_r( sqlsrv_errors(), true));
        }
    }
?>
  • 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-16T04:42:03+00:00Added an answer on May 16, 2026 at 4:42 am

    Without running your code locally, I would suggest you look into DB locking issues. If you are really updating your DB records a number of times a second, and trying to load you query page ever three seconds (your timeout is set to 3000, which is three seconds). If your query page takes longer than three seconds to load because of DB locking issues then your browser may having blocking issues, as it is waiting for the response from one request while firing a new ajax request.

    You could try putting some timeout code in your php query page.

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

Sidebar

Ask A Question

Stats

  • Questions 488k
  • Answers 488k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer System.Convert.ChangeType As per your example, you could do: int i… May 16, 2026 at 8:36 am
  • Editorial Team
    Editorial Team added an answer You may want to use the Project Trigger to start… May 16, 2026 at 8:36 am
  • Editorial Team
    Editorial Team added an answer You can easily check the contents of an object (e.g.… May 16, 2026 at 8:36 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

No related questions found

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.