NetworkError:405方法不允许AngularJS REST

Ben*_*Ben 11 angularjs

在AngularJS中,我有以下功能,它工作正常:

$http.get( "fruits.json" ).success( $scope.handleLoaded );
Run Code Online (Sandbox Code Playgroud)

现在我想将它从一个文件更改为一个url(使用一些甜蜜的Laravel 4返回json):

$http.get( "http://localhost/fruitapp/fruits").success( $scope.handleLoaded );

我得到的错误是:

"NetworkError: 405 Method Not Allowed - http://localhost/fruitapp/fruits"
Run Code Online (Sandbox Code Playgroud)

有什么问题?是因为fruit.json是"本地"而localhost不是?

Xes*_*ued 6

w3:

10.4.6 405 Method Not Allowed

The method specified in the Request-Line is not allowed for the resource 
identified by the Request-URI. The response MUST include an Allow header 
containing a list of valid methods for the requested resource.
Run Code Online (Sandbox Code Playgroud)

它表示URL:http://localhost/fruitapp/fruits服务器正在响应GET不允许该 方法.是一个POST还是PUT

  • 啊,你在localhost上运行你的Angular应用程序吗?这听起来像是[访问控制(CORS)]的问题(https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS) (6认同)