php - 来自 MySQL DB 的 AngularJS 值

标签 php mysql angularjs

我阅读了一些有关它的教程,但我不知道出了什么问题:

HTML

<!DOCTYPE html>
<html ng-app="dfuApp" ng-controller="dfuController">
    <head>
        <title>Angular JS Test</title>
    </head>
    <body>
        <div>
            current status: {{status}}
        </div>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
        <script type=”text/javascript” src="js/app.js"></script>
    </body>
</html>

aps.js

//Define an angular module for our app 
console.log('here');
var app = angular.module('dfuApp', [])

app.controller('dfuController', function ($scope, $http) {
    getStatus();
    function getStatus() {
    $http.get("../getStatus.php").success(function (data) {
        $scope.status = data; //the data are stored in projects
        });
    };
});

getStatus.php

<?php

$mysqli = new mysqli(credentials);

// The mysql database connection script

$query = "select statusid from metadata";
$result = $mysqli->query($query) or die($mysqli->error . __LINE__);

$arr = array();
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $arr[] = $row;
    }
}

//JSON-encode the response
echo $json_response = json_encode($arr);

此示例取自多个示例站点,例如 this , that最后this here .

我仔细检查了一遍,没有发现任何错误。 在我的控制台中,它显示:

[$injector:modulerr] http://errors.angularjs.org/1.3.15/$injector/modulerr?p0=dfuApp&p1=Error%3A…gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.15%2Fangular.min.js%3A17%3A381)

最终导致以下结果:

This error occurs when a module fails to load due to some exception. The error message above should provide additional context.

知道为什么这不起作用吗?我缺少什么?

最佳答案

应该是而不是

转换此内容

<script type=”text/javascript” src="js/app.js">

到此

<script type="text/javascript" src="js/app.js">

关于php - 来自 MySQL DB 的 AngularJS 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34808099/

相关文章:

php - 为什么 Doctrine 使用 WHERE IN 而不是 LIMIT?

php - 使用 HttpURLConnection 时,mysql 上的 $_POST 为空

PHP 通过 AJAX 调用注销

php - 返回数组中的 MySQL 行

php - 你如何使用 pdo 获取所有行?

mysql - 如何修复 MySQL 错误 1093

php - mysql_escape_string() 是否使 sql 注入(inject)变得不可能?

c# - WebApi 2 GET 在参数中有特殊字符

AngularJs ng-checked 使用函数

angularjs - 如何使用 npm 找到我的机器中已经安装的 angular-route