ajax呼び出しを使用してXML応答を取得しようとしています。 eXist DB REST API(1)。XMLHttpRequestはhttp:// localhost:8080/exist/rest/db/....をロードできません。Access Control-Allow-OriginによってNullが許可されていません
Google Chromeは私に次のコンソールエラー提供:FirefoxでFirebugのは、次のコンソールエラーを提供していますが
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
を:ここで
GET http://localhost:8080/exist/rest/db/movies?_query=%2Fmovies 200 OK X 35ms jquery.min.js(line 18)
は、コードのAjaxの部分である:
$.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);
}
});
私はこの同じいくつかの関連する問題を読んだ問題はありますが、私が試した解決策のどれにも不運は見つかりませんでした。次のように私はクロムを実行しようとしている
file:///.../index.html
:
chrome.exe --allow-file-access-from-files
また、私が試し
以下のようAJAXコードセグメントを自分のローカルマシンからアクセスさ含まのindex.htmlをファイルがオンラインホストに配置されるようにファイルを配置します。
http://www.<somedomain>.com/index.html
私が持っていたソリューションは、xmlからjsonpへのdataTypeを変更することでした。 REPONSEを受信しましたが、XMLであることが予想されるため、エラーがパースに関連なった、私はGoogle Chromeのコンソールで返される次の文で、考える:
Uncaught SyntaxError: Unexpected token <
とFirebugのコンソール:
XML can't be the whole program
[Break On This Error]
</exist:result>
movies...3302057 (line 528, col 15)
私の質問に戻って、eXist DBを使用してXML文書を正しく取得するにはどうすればよいですか?私は間違って何をしていますか?
お手数をお待ちしております。私はWeb開発にはまったく新しく、アイデアがなくなっています。
ありがとうございます!
その他の注意事項:直接任意のブラウザへのキー入力時に
jquery.min.js私が使用しているhttp://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
URI http://localhost:8080/exist/rest/db/movies?_query=%2Fmovies
作品に位置しています。
参考:
(1) - http://www.exist-db.org/exist/devguide_rest.xml;jsessionid=e7096vtg4l7gmocouhe6zhle
アップデート (1)次のようにサーバとDB存在し、私は実行することにより、CORSの問題を取り除くことができたようです:binに/ server.sh (UNIXの場合)またはbin¥server.bat(Windowsの場合)。
今、別のタイプの問題に遭遇しています。私はjquery.jsを使用してGoogle Chromeのコンソールで次のエラーを取得する:
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使用:エラーはどういう意味
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
を?私のコードのどの部分が間違っているのですか?
(2)更新1は、明らかに、私が直面した不要な問題です。サーバーモードが私のマシンで動作していなかったので、上記のエラーが表示されます。
[XmlHttpRequestエラー:Access-Control-Allow-OriginがOriginのnullを許可していません](http://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowedアクセス制御許可元) – jrummell