Reputation: 172
The issue is that either the PHP file isn't sending the data back or the JS file isn't catching the data.
The exact issue is that the data isn't display on the index.php page inside the <div>
.
I included code in the getDetails.php file to record what it was doing. It allows me to see that the query is running and data is being returned.
I have used similar code to this in the past without any problems. The only difference is that the previous code was working with MySQL. This code is dealing with an Access database. I don't know if I need to do anything special with the json_encode to deal with Access data.
I used an alert()
at the beginning of java.js to make sure that the java code is being called. It is. An alert right after the details = result
command never gets called.
INDEX.PHP:
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/plain; charset=UTF-8"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="java.js" type="text/javascript"></script>
</head>
<body>
<div id="reportDetails" class="reportDetails" align=center></div>
</body>
<html>
JAVA.JS:
jQuery(document).ready(function () {
var ra='7100913063';
$.ajax({
type: 'POST',
url: 'getDetails.php',
data: 'value=' + ra,
dataType: 'json',
cache: false,
success: function(result) {
details = result;
$("#reportDetails").text("");
for (var i = 0; i < details.length; i++) {
$("#reportDetails").append("<tr class='bottom'><td width=200 align=center class='bottom'>" + details[i][0] + "</td><td width=200 align=center class='bottom'>" + details[i][1] + "</td><td width=200 align=center class='bottom'> " + details[i][2] +"</td></td><td width=200 align=center class='bottom'> " + details[i][3] +"</td></td></tr>");
}
$("#reportDetails").append("</table>");
},
});
});
getDetails.php
<?php
include("../../scripts/adodb/adodb.inc.php");
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$ra = $_POST['value'];
set_time_limit(0);
date_default_timezone_set('America/Chicago');
$counter = 0;
$connect = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=//server/directory/database.mdb", '', '');
$query = "SELECT distinct ra, MIN(received) as startDate, MAX(completion) AS stopDate, MAX(status) as stat FROM cont WHERE ra = '" . $ra . "' GROUP BY ra";
$result = odbc_exec($connect,$query);
while(odbc_fetch_row($result)){
$radetails[0] = odbc_result($result,"ra");
fwrite($fh, $radetails[0]);
$radetails[1] = odbc_result($result,"startDate");
fwrite($fh, $radetails[1]);
$radetails[2] = odbc_result($result,"stopDate");
fwrite($fh, $radetails[2]);
$radetails[3] = odbc_result($result,"stat");
fwrite($fh, $radetails[3]);
}
fclose($fh);
echo json_encode($radetails);
?>
Upvotes: 1
Views: 72
Reputation: 172
I had the line "echo <br/>"
in my getDetails.php. Removed that line and it works now.
Upvotes: 1