【发布时间】:2014-05-04 12:45:19
【问题描述】:
我正在使用 AngularJS 在 MarkLogic 7 XML 数据库之上构建一个 web 应用程序。我正在使用 MarkLogic 提供的 REST API 来访问数据库。我在控制器中使用的代码如下。
app.controller("mainController", function($scope, $http){
var addr = 'http://localhost:8011/v1/search?q=test&options=newtest';
$http({method:'GET', url: addr})
.success(function(data){
alert('Success');
console.log(data);
});
});
现在,当我打开视图时,控制台中会记录一个“错误请求”错误。
OPTIONS http://localhost:8011/v1/search?q=test&options=newtest 400 (Bad Request)
angular.min.js:99
OPTIONS http://localhost:8011/v1/search?q=test&options=newtest No 'Access-Control-Allow-
Origin' header is present on the requested resource. Origin 'null' is therefore not
allowed access. angular.min.js:99
XMLHttpRequest cannot load http://localhost:8011/v1/search?q=test&options=newtest. No
'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null'
is therefore not allowed access. index.html:1
是否需要在 MarkLogic 服务器上配置任何设置以使 API 可访问?请帮忙。
谢谢, 克里希纳
【问题讨论】:
-
搜索错误信息,
No 'Access-Control-Origin' header is present on the requested resource -
您好 Jason,我已尝试按照针对该问题的建议使用 jsonp。但是,我不能在请求中使用回调参数,因为 MarkLogic 不理解它。此外,当我尝试使用 $http.jsonp(url).success(data) 方法时,它给了我一个意外的 ':' 错误。我试图通过在端口号前转义“:”来解决此问题,但随后出现“连接被拒绝”错误。所以那个解决方案对我不起作用。
标签: json angularjs rest marklogic