Angularjs CORS HTTP有时只发送Options

时间:2013-11-17 14:55:29

标签: javascript angularjs cors

我意识到这是一个CORS问题(跨域资源共享),但是这个网站上的其他答案都没有给出真正的答案,只有部分答案。

JSONP Fiddle代码以防它消失: HTML:

<div ng-app="test">
<div ng-controller="myCtrl">
        <ul>
            <li ng-repeat="person in people">
            {{person.name}}
            </li> 
        </ul>
    </div>
</div>

js:

angular.module('test',[]).controller('myCtrl',function($scope,$http){
            $http.jsonp('http://filltext.com?rows=10&name={firstName}&callback=JSON_CALLBACK').
                success(function(data){
                    console.log('jsonp: ' + data.toSource())
                    $scope.people=data;
                });
        });

GET Fiddle这适用于jsfiddle网站(发送OPTIONS和GET),当从我的本地实例运行时,我只有中止状态的GET?

html(与上述相同)

JS:

angular.module('test',[]).controller('myCtrl',function($scope,$http){
            $http.get('http://filltext.com?rows=10&name={firstName}').
                success(function(data){
                    console.log('get: ' + data.toSource())
                    $scope.people=data;
                });
        });

filltext.com的卷曲输出:

C:\curl>curl -I -L filltext.com  
HTTP/1.1 200 OK  
Content-Length: 0  
Content-Type: text/html  
Server: Microsoft-IIS/8.0  
X-Powered-By: ASP.NET  
Access-Control-Allow-Origin: *  
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept  
Set-Cookie:   ARRAffinity=fe3393d4a10cdae36cc37fe2cf3d22e22d54b3e9d480133b259cf01a6b50cf18;Path=/;Domain=filltext.com  
Set-Cookie: WAWebSiteSID=799ddfe9633c490a8bca027fc70cf991; Path=/; HttpOnly  
Date: Sun, 17 Nov 2013 15:10:34 GMT  

Firebug输出:

enter image description here

修改 我的环境是一个vanilla Apache部署,只有

Access-Control-Allow-Origin: *

是唯一的改变。

0 个答案:

没有答案