XMLHtt prequest无法加载的http://本地主机:8080 /存在/ REST / DB / ....产地空不被允许访问控制 - 允许 - 原产地 [英] XMLHttpRequest cannot load http://localhost:8080/exist/rest/db/.... Origin null is not allowed by Access-Control-Allow-Origin

查看:263
本文介绍了XMLHtt prequest无法加载的http://本地主机:8080 /存在/ REST / DB / ....产地空不被允许访问控制 - 允许 - 原产地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用AJAX调用行为的存在DB REST API来检索XML响应(1)。

谷歌浏览器为我提供了以下控制台错误:

Google Chrome provides me the following console error:

XMLHttpRequest cannot load XMLHttpRequest cannot load http://localhost:8080/exist/rest/db/movies?_query=%2Fmovies. Origin null is not allowed by Access-Control-Allow-Origin Origin null is not allowed by Access-Control-Allow-Origin

虽然萤火虫在Firefox中提供了以下控制台错误:

While Firebug in Firefox provides the following console error:

GET http://localhost:8080/exist/rest/db/movies?_query=%2Fmovies 200 OK X 35ms jquery.min.js(line 18)

这里是code中的AJAX部分:

Here is the ajax portion of the code:

$.ajax({
                    type: 'GET',
                    dataType: 'xml',
                    url: 'http://localhost:8080/exist/rest/db/movies',
                    data: {
                        _query: _query_value,
                        _key: _key_value,
                        _indent: _indent_value,
                        _encoding: _encoding_value,
                        _howmany: _howmany_value,
                        _start: _start_value,
                        _wrap: _wrap_value,
                        _source: _source_value,
                        _cache: _cache_value
                    },
                    success: function(resp){
                        alert("Resp OK!");
                        console.log(resp);
                    },
                    error: function(hqXHR, textStatus, errorThrown){
                        var x=0;
                        alert("fail0 " + hqXHR + " " + textStatus + " " + errorThrown);
                    }
                });

我已阅读此相同的问题的一些相关的问题,但我发现没有运气的任何,我试图解决的。

I have read some related issues on this same problem, but I have found no luck with any of the solution that I tried.

,其中包含以上Ajax code段中的index.html是从我的本地机器访问如下:

The index.html which contains the ajax code segment above is accessed from my local machine as follows:

file:///.../index.html

我曾尝试执行铬如下:

I have tried executing chrome as follows:

chrome.exe --allow-file-access-from-files

另外,我试图将文件部署到一个网上的主机,以便它位于

Also, I tried to deploy the file to an online host so that it is located at

http://www.<somedomain>.com/index.html

这是我最接近的解决办法是改变的具体的数据类型从XML到JSONP。被接收的效应初探,但由于它有望成为XML,错误变得与分析,我认为,与谷歌Chrome控制台返回以下语句:

The closest solution that I had was to change the dataType of the from xml to jsonp. The reponse was received, but since it is expected to be xml, the error became related to parsing, I think, with the following statement returned by the Google Chrome console:

Uncaught SyntaxError: Unexpected token <

和Firebug的控制台:

and Firebug console:

XML can't be the whole program
[Break On This Error]   
</exist:result>
movies...3302057 (line 528, col 15)

让我们回到我的问题,如何通过eXist的数据库,我可以适当地检索XML文档?我究竟做错了什么?

期待您的帮助。我是很新的网络开发和正在运行的想法。

Looking forward to your help. I'm quite new to web development and am running out of ideas.

在此先感谢!

其他注意事项:

这是我使用的是坐落在的 http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js

The jquery.min.js that I'm using is located at http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js

的URI 的http://本地主机:8080 /有/ REST / DB /电影_query =%2Fmovies 时,直接键入任何浏览器的工作原理

The URI http://localhost:8080/exist/rest/db/movies?_query=%2Fmovies works when directly keyed in to any browser.

参考:

(1) - http://www.exist-db.org/exist/devguide_rest.xml;jsessionid=e7096vtg4l7gmocouhe6zhle

更新 (1)看来,我是能够摆脱通过运行CORS问题存在DB作为服务器如下:斌/ server.sh(在UNIX中)或BIN \ server.bat(在Windows中)

Updates (1) It seems that I was able to get rid of the CORS problem by running eXist DB as a server as follows: bin/server.sh (in UNIX) or bin\server.bat (in Windows).

现在,我遇到了另一种类型的问题,虽然。我使用的jquery.js得到以下错误的谷歌浏览器控制台:

Now, I am running into another type of problem, though. I get the following error in the Google Chrome console using jquery.js:

GET http://localhost:8080/exist/rest/db/movies?_query=%2Fmovies  jquery.js:8240
jQuery.ajaxTransport.send jquery.js:8240
jQuery.extend.ajax jquery.js:7719
(anonymous function) index.html:43
jQuery.event.dispatch jquery.js:3332
jQuery.event.add.elemData.handle.eventHandle jquery.js:2941

和使用jquery.min.js:

and using jquery.min.js:

GET http://localhost:8080/exist/rest/db/movies?_query=%2Fmovies  jquery.min.js:18
f.support.ajax.f.ajaxTransport.send jquery.min.js:18
f.extend.ajax jquery.min.js:18
(anonymous function) index.html:43
f.event.handle jquery.min.js:17
f.event.add.i.handle.k jquery.min.js:16

什么是错误的意思吗?我的哪个code部分我在做什么错?

What does the error mean? Which part of my code am I doing wrongly?

(2)更新1,显然,是我遇到不必要的问题。服务器模式是不工作与我的机器,这就是为什么错误上面出现了。

(2) Update 1, apparently, is an unnecessary problem that I faced. The server mode wasn't working with my machine that's why the errors above showed up.

推荐答案

这是一个跨域请求,是不允许的。从本地主机而不是文件测试://。此外,远程服务器需要返回正确 CORS 的标头如果打算工作横-Domain比JSONP其他任何数据类型。该JSONP数据类型并不意味着返回XML。

This is a cross-domain request and is not permitted. Test from localhost instead of file://. Additionally, the remote server needs to return the proper CORS headers if it is intended to work cross-domain with any dataType other than JSONP. The JSONP datatype is not meant for returning XML.

这篇关于XMLHtt prequest无法加载的http://本地主机:8080 /存在/ REST / DB / ....产地空不被允许访问控制 - 允许 - 原产地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆