Php 使用angularJs进行轮询

Php 使用angularJs进行轮询,php,angularjs,polling,Php,Angularjs,Polling,我只想为客户端的当前更新建立轮询连接 我不能让它工作: var app = angular.module('url', []); app.factory('Poller', function($http,$q){ return { poll : function(api){ var deferred = $q.defer(); $http.get(api).then(function (response) {

我只想为客户端的当前更新建立轮询连接

我不能让它工作:

var app = angular.module('url', []);

app.factory('Poller', function($http,$q){
    return {
        poll : function(api){
            var deferred = $q.defer();
            $http.get(api).then(function (response) {
                deferred.resolve(response.data);
            });
            return deferred.promise;
        }

    }
});

app.directive('ngBlur', function(){
    return function(scope, elem, attrs){
        elem.bind('blur', function(){
            scope.$apply(attrs.ngBlur);
        })
    }
});

app.controller('UrlCtrl', function($scope, $filter, $http, $location, Poller){

    $scope.myts = Poller.poll('localhost:8888/mytest.php');
    $scope.mydate = $scope.myts.then(function(data){
        return $filter('date')(data,'yyyy-MM-dd HH:mm:ss Z');
    });
    var Repeater = function () {
        $scope.$apply(function () {
            $scope.myts = Poller.poll('localhost:8888/mytest.php');
            $scope.mydate = $scope.myts.then(function(data){
                return $filter('date')(data,'yyyy-MM-dd HH:mm:ss Z');
            });
        });
    };
    var timer = setInterval(Repeater, 1000);


    $scope.urls = [];

    $http.get("http://localhost:8888/web-service.php")
        .success(function(data) {
            data.URLs.forEach(function(url){
                $scope.urls.push({
                    name : url.name,
                    preferred : false
                });

            })
        })

    $scope.$watch('urls', function(){
        $scope.chosenURL = $filter('filter')($scope.urls, {preferred:true}).length;
        $scope.allchecked = !$filter('filter')($scope.urls, {preferred:false}).length;
    }, true)

    if($location.path() == ''){ $location.path('/')}
    $scope.location = $location;
    $scope.$watch('location.path()', function(path){
        $scope.statusFilter =
            (path == '/active') ? {preferred : true} :
            null;
    });

    $scope.removeUrl = function(index){
        $scope.urls.splice(index,1);
    }

    $scope.addUrl = function(){
        $scope.urls.push({
            name : $scope.newurl,
            preferred : false
        });
        $scope.newurl = '';
    }

    $scope.editUrl = function(url){
        url.editing = false;
    }

    $scope.checkAllUrl = function(allchecked){
        $scope.urls.forEach(function(url){
            url.preferred = allchecked;
        })
    };
});
mytest.php

<?php 
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
echo time()*1000;

?>

这里是我得到的错误:

未能加载资源:net::ERR_UNKNOWN_URL_SCHEME
localhost:8888/mytest.php
未能加载资源:服务器 响应状态为404(未找到)
http://localhost:63342/DeliciousJS/js/app.js.map
加载失败 资源:服务器响应状态为404(未找到) 8加载资源失败:net::错误\u未知\u URL\u方案
localhost:8888/mytest.php
OPTIONS
localhost:8888/mytest.php
net::ERR_UNKNOWN_URL_SCHEME angular.min.js:97(匿名函数) angular.min.js:97o angular.min.js:93l angular.min.js:92l.(匿名) 函数)angular.min.js:94poll app.js:7(匿名函数) app.js:32e.$eval angular.min.js:86e.$apply angular.min.js:86中继器 app.js:31选项
localhost:8888/mytest.php
net::ERR\u未知\u URL\u方案

当我直接在chrome上尝试时,为什么找不到有效的url


Thx对于您的帮助

仅使用mytest.php而不是localhost:8888/mytest.php。。如果你想使用完整的url,那么键入可能无法解决你的问题,但你应该升级到新的angularJs版本,你使用的是1.0.3,最后一个是1.2.23我需要获取完整链接,因为我的apache位于localhost:8888,而我的angular应用程序不在@我不明白你的答案,因为这是我输入的。