Angular2 - PHP - EXCEPTION:响应状态:0表示URL:null

时间:2017-02-24 12:52:40

标签: php angularjs

所以有很多关于这个的帖子,但它们对我来说都不是很清楚 有些人甚至似乎在python(???)

中给出答案

我尝试访问这个php文件(wamp在端口80上侦听)

<?php
    header('Content-type: application/json');
    echo '{"test":"test"}';
?>
我调用的角度服务就是这个

从@ angular / core&#39;导入{Injectable}; 从&#39; @ angular / http&#39;;

导入{Http}

@Injectable() 导出类DataService {     构造函数(私有http:Http)     {     }

authenticate = function(login:string, pass:string) : void
{
    this.http.get("http://localhost/data.php")
        .subscribe( 
            (res:any) => 
            {
                console.log('res', res.json());
            }
        );
};

}

我收到上述错误

编辑:

      <?php
    //header('Content-type: application/json');
    header('Access-Control-Allow-Methods', 'POST,GET,OPTIONS,PUT,DELETE');
    header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');   
    header('Access-Control-Allow-Origin: *');
    echo '{"test":"test"}';
?>

感谢

0 个答案:

没有答案