I have a php page which returns a table representing a query sent to a MySQL database. So far it has worked in every case except now that I'm trying to use it to call a stored procedure, in which case the readystate is staying at 1 and never completing.
I have logged the results of the php file both in an error log and looked at the response from the request using firebug, both of which show a correct result.
So for my question: Why isn't this returning properly?
Here are the relevant javascript functions:
Note that the $() function simply returns an element from the page and the notify method is printing debug information to a div.Code:function customizeType() { $("custom-header").innerHTML = ""; $("custom-top").innerHTML = ""; $("custom-middle").innerHTML = ""; $("custom-bottom").innerHTML = ""; $("custom-footer").innerHTML = ""; switch(type) { case "Transaction": loadBottom("transaction"); break; } } function loadBottom(item) { requestItem(item, showCustomBottom); notify("request to load "+item+" in bottom position sent"); } function showCustomBottom(response) { $("custom-bottom").innerHTML = response; notify("bottom loaded"); } function requestItem(item, callback) { switch(item) { case "query": query = baseQuery+" "+type+" "+whereClause+" "+orderClause; requestQuery(query, item, callback); break; case "record": if(selected){ openID = selected.firstChild.innerHTML; requestRecord(type, openID, callback); }else{ callback(""); } break; case "newRecord": requestNewRecord(type, callback); break; case "transaction": query = "call GetStats()"; requestQuery(query, item, callback); notify("request for query: '"+query+"' sent"); //notify("callback is "+callback); break; } } function requestQuery(query, name, callback) { if (window.XMLHttpRequest){ request = new XMLHttpRequest(); }else{ // For IE 5 and 6 compatibility request = new ActiveXObject("Microsoft.XMLHTTP"); } request.open("POST","query.php"); request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); request.onreadystatechange=function() { notify("query ready state is "+request.readyState); if(request.readyState==4 && request.status==200){ callback(request.responseText); } }; request.send("query="+query+"&name="+name); }
When the page is loaded, this is the final result of the notify statements:
query ready state is 1
query ready state is 2
query ready state is 3
query ready state is 4
query ready state is 1
request for query: 'call GetStats()' sent
request to load transaction in bottom position sent
query ready state is 1
query ready state is 1
query ready state is 1
Also, here is the query.php file:
After the page loads, the error log shows correct results for all queries.PHP Code:<?php
$debug = true;
$fullDoc = "";
set_error_handler("notify");
$db = new mysqli("localhost", "Organizer", "Organizer", "organizer");
/* check connection */
if (mysqli_connect_errno()) {
notify(0, mysqli_connect_error(), "query.php", 7);
exit();
}
if(!($result = $db->query($_POST["query"]))){
notify(0, $db->error, "query.php", 12);
exit();
}
if($debug){
logMessage("Query succeeded: ".$_POST["query"]);
logMessage("Result set has ".$result->field_count." fields");
}
$fullDoc .= "<table id = '".$_POST["name"]."' class = 'queryTable'>";
$fullDoc .= "<tr id = 'headers' class = 'queryHeaderRow'>";
$x = 0;
while ($x < $result->field_count)
{
$meta = $result->fetch_field_direct($x);
$fullDoc .= "<td id = 'header-".$x."' class = 'queryHeader'>".$meta->name."</td>";
$x++;
}
$fullDoc .= "</tr>";
$r = 0;
while($row = $result->fetch_array())
{
logMessage("-Processing row ".$r);
$fullDoc .= "<tr id = 'row-".$r."' class = 'queryResultRow'>";
$x = 0;
while ($x < $result->field_count)
{
$fullDoc .= "<td id = '".$r.",".$x."' class = 'queryResult'>".$row[$x]."</td>";
$x++;
}
$fullDoc .= "</tr>";
$r++;
}
$fullDoc .= "</table>";
$db->close();
if($debug){
logMessage($fullDoc);
}
echo $fullDoc;
function notify($errno, $errstr, $errfile, $errline)
{
$message = "Error Occurred in ".$errfile." at line ".$errline.": ".$errstr;
echo $message;
logMessage($message);
}
function logMessage($message)
{
$logDir = "C:\\users\\Doug\\Desktop\\Organizer.log";
error_log($message."\r\n", 3, $logDir);
}
?>
I have spent a couple days trying to figure this one out so far, so any help would be appreciated.


Reply With Quote

Bookmarks