如何在我的Angular项目中设置php?

时间:2016-06-11 03:18:28

标签: javascript php angularjs

我正在尝试设置一个具有PHP后端的角度项目。我的项目设置如下:

project
   -app
     -api
       -test.php
     -scripts
       -app.js
       -test.controller.js
     -css
     -images
     ...others

在我的test.controller.js

angular.module('myApp')
  .controller('MainCtrl', function ($http) {

 $http.get('api/test.php').then(function(res) {
     console.log(res)
 })
 ...more
});

在我的test.php里面

<?php
    ..php codes
    ..calculate stuff.
    ..generate $result

echo json_encode($result);

出于某种原因,当我加载页面时,我从请求中看到的只是我的整个test.php代码而不是我需要的数据。

例如:
我得到的回报

"<?php↵header("Content-Type: application/json", true);...more...

我确实有我的虚拟主机设置,我不确定出了什么问题。有人能帮帮我吗?

0 个答案:

没有答案