dousha1394 2015-10-02 04:46
浏览 10
已采纳

angularjs php文件不执行

i'm trying to execute a promise in angular, this is my service code :

var carsService = function ($http, $q, $log, $rootScope) {
    var service = this;

    service.getInfo = function () {

        var defer = $q.defer();

        $http.get($rootScope.endPoint + 'cars.php?load=t')
            .success(function (data) {
                defer.resolve(data);
            })
            .error(function (data, status, headers, config) {
                defer.reject({
                    n: 1000,
                    msj: 'some error msg'
                });
                $log.log(data + ' ' + status + ' ' + headers + ' ' + config);
            });

        return defer.promise;
    };
};

and this is how i called from my controller :

CarsService.getInfo()
            .then(function (data) {
                console.log(data);
            }, function (err) {
                swal("ERROR", "some error msg.", "error");
            }
        );

and this is my cars.php file :

<?php
  var $r = array('a'=>1,'b'=>2);
  print json_encode($r);
?>

what i'm expecting is the console print an array , but what i get is the php code printed.

enter image description here

PHP is running :

enter image description here

I tried with POSTMAN too :

enter image description here

Any ideas guys ???? thanks ...

  • 写回答

1条回答 默认 最新

  • dongliang9682 2015-10-02 07:09
    关注

    Your $rootScope.endPoint variable is probably incorrect.

    The GET call in PostMan is made to localhost:63342 (Webstorm LiveEdit?) and XAMPP is running at localhost:8090. The cars.php file has to be executed on your Apache server and the GET call has to be directed to localhost:8090/path_to_cars.php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义