I am trying to get an XML response using ajax calls to the eXist DB (1) REST API.
Google Chrome provides me with 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
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)
Here is the piece of ajax 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 read some related issues on the same issue, but I did not find any luck in the solution I tried.
The index.html pointer containing the above ajax code segment is accessed from my local machine as follows:
file:
I tried chrome as follows:
chrome.exe --allow-file-access-from-files
In addition, I tried to deploy the file to an online host so that it was in
http:
The closest solution I had was to change dataType from xml to jsonp. An answer was received, but since it was 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 <
and Firebug console:
XML can't be the whole program [Break On This Error] </exist:result> movies...3302057 (line 528, col 15)
Returning to my question, how can I get the XML document correctly through eXist DB? What am I doing wrong?
Looking forward to your help. I am completely new to web development and I am running out of ideas.
Thanks in advance!
Other notes:
jquery.min.js that I use is located at http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
URI http://localhost:8080/exist/rest/db/movies?_query=%2Fmovies
works when connected directly to any browser.
Reference:
(1) - http:
Update (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 (on UNIX) or bin \ server.bat (on Windows).
Now I am faced with a different type of problem. I get the following error on 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
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
What does the error mean? What part of the code am I doing wrong?
(2) Update 1 seems to be an unnecessary issue that I ran into. Server mode did not work with my machine, so the errors above appeared.