1

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);
?>
Lughino
  • 4,060
  • 11
  • 31
  • 61
user1621308
  • 172
  • 3
  • 15
  • How about throwing an ajax failure-handler in there, and seeing if/what comes back? Also, have you tried debugging "java.js" and seeing what happens on "success" - if it even executes? anything in the console log? – Michael Paulukonis Oct 16 '13 at 20:10
  • Most likely your php isn't returning json. – Kevin B Oct 16 '13 at 20:11
  • Have you looked for errors in your browser console? That should tell you exactly where the problem is. – Reinstate Monica Cellio Oct 16 '13 at 20:13
  • What does Firebug tell you is being sent and returned? Debugging AJAX blind isn't useful – Machavity Oct 16 '13 at 20:14
  • If you're using Firefox, try using Firebug. Look at the console tab then click on the ...[url]...getDetails.php and finally the Response tab. This will show what's being returned. – rrtx2000 Oct 16 '13 at 20:19
  • I keep forgetting about the console. It showed a
    in the result set, so I took that out and it works now. I am obviously too stupid to live. And I do realize that java and javascript aren't the same thing, but figured I would keep the name java.js since it is short and sweet.
    – user1621308 Oct 16 '13 at 20:25
  • Put your answer into... an answer. Then accept it in a day or two. – Michael Paulukonis Oct 16 '13 at 20:35

1 Answers1

1

I had the line "echo <br/>" in my getDetails.php. Removed that line and it works now.

user1621308
  • 172
  • 3
  • 15