mardi 3 mars 2015

AngularJS .get Method Causing Internal Error 500

I've got a working version of the code on my local machine using xampp but when I uploaded it to my Raspberry Pi it seems to go haywire.


Basically I've got an angularjs script calling a file called dbConn.php which is in the same directory and works on a local machine but doesn't when uploaded to a Pi.


Any help with this would be greatly appreciated:



function raspberryController($scope, $http, $timeout) {
var poll = function() {
$timeout(function() {
try{
$http.get("dbConn.php")
.success(function(response) {$scope.names = response;})
.error(function(data, status, header, config) {
console.log(alert, status, header, config);
});
} catch (e) {
console.log("Got an error!",e);
throw e; // rethrow to not marked as handled
}
poll();
}, 1000);
}
poll();
}


dbConn.php



<?php
//$db = new SQLite3('system/modules/test.db');
header("Access-Control-Allow-Origin: *");
try{
$dbh = new PDO('sqlite:system/test.db') or die("cannot open db");
} catch(Exception $e) {echo $e->getMessage(); }
$query = 'SELECT * FROM connected;';

$results = $dbh->query($query);

$outp = '[';
foreach($dbh->query($query) as $row){
if ($outp != "[") {$outp .= ",";}
$outp .= ' { "ID":"' . $row[0] .'",';
$outp .= '"IP":"' . $row[1] .'",';
$outp .= '"CONNECTED":"' . $row[2] .'",';
$outp .= '"LEASE_TIME":"' .$row[3] .'" } ';

}
$outp .= ']';

echo($outp);
?>

Aucun commentaire:

Enregistrer un commentaire