Php Angular Js$http.get CORS问题-在Jquery中工作

Php Angular Js$http.get CORS问题-在Jquery中工作,php,jquery,ajax,angularjs,Php,Jquery,Ajax,Angularjs,大家好,我是angularjs新手,我正在将我的应用程序从jquery转换为angularjs。但是我在AngularJS中遇到了ajax请求方面的困难。我的代码在jquery中运行良好 Angularjs代码: links.serverurl = My Another Server Address which is defined another location $scope.submit = function () { console.log(this.formData); $

大家好,我是angularjs新手,我正在将我的应用程序从jquery转换为angularjs。但是我在AngularJS中遇到了ajax请求方面的困难。我的代码在jquery中运行良好

Angularjs代码:

 links.serverurl = My Another Server Address which is defined another location
 $scope.submit = function () {

 console.log(this.formData);

 $http.get(links.serverUrl).success(function (response) {  
   console.log(response);
 });
JQuery工作代码:

var url = "http://pbc.mydev786.com/";

$.get(url+"?"+data,function(response){
  $("div[data-role='page']").hide();
  $("#showbill").show();
  $(".billresult").html(response);
});
我的Php标题:

 header('Access-Control-Allow-Origin: *');
 header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PATCH, DELETE');  
 header('Access-Control-Allow-Headers: Origin, Content-Type,X-Requested-With');
AngularJs配置:

$myapp.config(['$routeProvider', '$httpProvider', function ($routeProvider, $httpProvider) {
        $routeProvider
                .when('/', {templateUrl: "home.html"})
                .when('/electricity', {templateUrl: "electricity.html"})
                .when('/evo', {templateUrl: "evo.html"})
                .when('/ptcl', {templateUrl: "ptcl.html"})
                .when('/suigas', {templateUrl: "suigas.html"})
                .when('/iesco', {templateUrl: "iesco.html"})
                .when('/lesco', {templateUrl: "lesco.html"})
                .when('/fesco', {templateUrl: "fesco.html"})
                .when('/kesc', {templateUrl: "kesc.html"})
                .when('/extra', {templateUrl: "extra.html"})
                .when('/myaccount', {templateUrl: "myaccount.html"});
        $httpProvider.defaults.useXDomain = true;
        delete $httpProvider.defaults.headers.common['X-Requested-With'];
    }]);
请求的标题:

Accept  application/json, text/plain, */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Content-Length  20
Content-Type    text/plain; charset=UTF-8
Host    pbc.mydev786.com
Origin  http://localhost:8383
Referer http://localhost:8383/PakistanCheckBill/
User-Agent  Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0
Connection  keep-alive
Content-Encoding    gzip
Content-Type    text/html
Date    Tue, 20 Jan 2015 11:47:43 GMT
Server  nginx/1.6.2
Transfer-Encoding   chunked
响应标题:

Accept  application/json, text/plain, */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Content-Length  20
Content-Type    text/plain; charset=UTF-8
Host    pbc.mydev786.com
Origin  http://localhost:8383
Referer http://localhost:8383/PakistanCheckBill/
User-Agent  Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0
Connection  keep-alive
Content-Encoding    gzip
Content-Type    text/html
Date    Tue, 20 Jan 2015 11:47:43 GMT
Server  nginx/1.6.2
Transfer-Encoding   chunked

只有这一点对我有效,没有任何angularjs的把戏帮助我

# CORS Headers 
<ifModule mod_headers.c>
Header always set Access-Control-Allow-Origin: "*"
Header always set Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
Header always set Access-Control-Allow-Headers "X-Requested-With, content-type"
</ifModule>
#CORS头文件
标题始终设置访问控制允许原点:“*”
Header始终设置访问控制允许方法“POST、GET、PUT、DELETE、OPTIONS”
标头始终设置访问控制允许标头“X-request-With,content-type”

我还尝试用php设置这些标题,但不起作用,我不知道为什么。

对我来说不起作用,问题用更多代码编辑,如果有错误,你会得到什么?服务器文件的响应是什么?跨源请求被阻止:同源策略不允许读取远程资源[。这可以通过将资源移动到同一个域或启用CORS来解决。您确定您的服务器用所需的头响应什么吗?这是唯一适合我的解决方案。在我的代码中修改头导致错误:头已发送。顺便说一句,jquery工作正常,只有angular有问题。