Hi,
I just installed basex for the first time and I am very impressed and really looking forward to using it. Thanks for making such a great tool available for free!
I'm not really a developer so this might be an obvious question: using basex's http server, what is the best strategy for ajax-style communication between browser and db?
I am aware of a few approaches:
1) direct httprequest to host:8984/my_db/somequery, but going across ports seems to violate "same origin policy"
2) using jsonp 3) calling from browser to server-script (like the php example in basex docs), which handles request to the db
All responses are greatly appreciated, Colin
Hi Colin,
I'm glad you enjoy BaseX, and the newly added http server.
I guess I'd go with 2 or 3 - where 3 maybe has the caveat that you have to have another server running. I made some good experiences using jQuery with jsonp, it's especially useful if you directly return json encoded results, our wiki [1] has some examples on serializing json.
Hope this helps, feel free to further discuss (or report your experiences on) this topic in our list.
Thanks
Michael
Am 18.10.2011 um 16:43 schrieb colin mcenearney:
Hi,
I just installed basex for the first time and I am very impressed and really looking forward to using it. Thanks for making such a great tool available for free!
I'm not really a developer so this might be an obvious question: using basex's http server, what is the best strategy for ajax-style communication between browser and db?
I am aware of a few approaches:
- direct httprequest to host:8984/my_db/somequery, but going across ports seems to violate "same origin policy"
- using jsonp
- calling from browser to server-script (like the php example in basex docs), which handles request to the db
…[1] sorry I forgot http://docs.basex.org/wiki/JSON_Functions
:-) Michael
Am 18.10.2011 um 16:59 schrieb Michael Seiferle:
I guess I'd go with 2 or 3 - where 3 maybe has the caveat that you have to have another server running. I made some good experiences using jQuery with jsonp, it's especially useful if you directly return json encoded results, our wiki [1] h
Dear Colin,
thanks for your e-mail.
I'm not really a developer so this might be an obvious question: using basex's http server, what is the best strategy for ajax-style communication between browser and db?
As Michael already pointed out, there is no "unique" strategy how to use BaseX with AJAX. One popular way is to use our new "json" serialization method, which allows you to directly return JSON from BaseX. A small example:
1. Start the HTTP server via "basexhttp -l" (the -l flag will communicate with the local database context; this way, no other socket connection will be used)
2. Via REST, retrieve a document or run a query and specify "jsonml" as output method: http://localhost:8984/rest/database/doc.xml?method=jsonml
This way, the XML result will be directly serialized, using the JSONML syntax. If you have created your XML documents from JSON input files, you may as well use "json" as serialization format. Pleave check out our documentation as well:
http://docs.basex.org/wiki/JSON_Functions
Feel free to ask if this is not exactly what you are looking for. Christian
Hi Christian and Michael, and everyone.
Thanks for your replies.
I'm still having a little difficulty.Attempting to return results with method=jsonml I still get this error (using jquery's ajax methods):
thrown error: [Exception... "Access to restricted URI denied" code: "1012"
which I think is a result of sending an http-request across different ports.
I think my question might be clearer with some background: My idea for a simple app to learn the db is a blog, where each entry has its own xml file which contains, among other things, chunks of valid xhtml. I was envisioning a very simple interaction where javascript sends a get or post request and the db returns bits of xhtml.
Can this be done without the use of additional server-side scripting? Maybe with direct calls to an xquery file like http://mysite.com/blog/blog.xq?categ=xmldb&level=beginner ?
Colin
________________________________ From: Christian Grün christian.gruen@gmail.com To: colin mcenearney colinmcenearney@yahoo.com Cc: "basex-talk@mailman.uni-konstanz.de" basex-talk@mailman.uni-konstanz.de Sent: Tuesday, October 18, 2011 11:54 AM Subject: Re: [basex-talk] ajax and http server - cross-domain, jsonp or proxy?
Dear Colin,
thanks for your e-mail.
I'm not really a developer so this might be an obvious question: using basex's http server, what is the best strategy for ajax-style communication between browser and db?
As Michael already pointed out, there is no "unique" strategy how to use BaseX with AJAX. One popular way is to use our new "json" serialization method, which allows you to directly return JSON from BaseX. A small example:
1. Start the HTTP server via "basexhttp -l" (the -l flag will communicate with the local database context; this way, no other socket connection will be used)
2. Via REST, retrieve a document or run a query and specify "jsonml" as output method: http://localhost:8984/rest/database/doc.xml?method=jsonml
This way, the XML result will be directly serialized, using the JSONML syntax. If you have created your XML documents from JSON input files, you may as well use "json" as serialization format. Pleave check out our documentation as well:
http://docs.basex.org/wiki/JSON_Functions
Feel free to ask if this is not exactly what you are looking for. Christian
Supporting JSON-P would be great; Michael mentioned that BaseX supports it, but a search for JSON-P or 'callback' in the Wiki turns up empty...
What's the callback argument used in JSON-P called? callback?
- Godmar
On Fri, Oct 21, 2011 at 12:51 AM, colin mcenearney colinmcenearney@yahoo.com wrote:
Hi Christian and Michael, and everyone. Thanks for your replies.
I'm still having a little difficulty. Attempting to return results with method=jsonml I still get this error (using jquery's ajax methods):
thrown error: [Exception... "Access to restricted URI denied" code: "1012"
which I think is a result of sending an http-request across different ports.
I think my question might be clearer with some background: My idea for a simple app to learn the db is a blog, where each entry has its own xml file which contains, among other things, chunks of valid xhtml. I was envisioning a very simple interaction where javascript sends a get or post request and the db returns bits of xhtml.
Can this be done without the use of additional server-side scripting? Maybe with direct calls to an xquery file like http://mysite.com/blog/blog.xq?categ=xmldb&level=beginner ?
Colin
From: Christian Grün christian.gruen@gmail.com To: colin mcenearney colinmcenearney@yahoo.com Cc: "basex-talk@mailman.uni-konstanz.de" basex-talk@mailman.uni-konstanz.de Sent: Tuesday, October 18, 2011 11:54 AM Subject: Re: [basex-talk] ajax and http server - cross-domain, jsonp or proxy?
Dear Colin,
thanks for your e-mail.
I'm not really a developer so this might be an obvious question: using basex's http server, what is the best strategy for ajax-style communication between browser and db?
As Michael already pointed out, there is no "unique" strategy how to use BaseX with AJAX. One popular way is to use our new "json" serialization method, which allows you to directly return JSON from BaseX. A small example:
- Start the HTTP server via "basexhttp -l" (the -l flag will
communicate with the local database context; this way, no other socket connection will be used)
- Via REST, retrieve a document or run a query and specify "jsonml"
as output method: http://localhost:8984/rest/database/doc.xml?method=jsonml
This way, the XML result will be directly serialized, using the JSONML syntax. If you have created your XML documents from JSON input files, you may as well use "json" as serialization format. Pleave check out our documentation as well:
http://docs.basex.org/wiki/JSON_Functions
Feel free to ask if this is not exactly what you are looking for. Christian
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Dear Godmar,
Sorry if my recent reply was misleading there is no explicit support for jsonp at the moment but to build it yourself (pad the result with the help of xquery).
I guess it could be added in case s/o wants to do it :-)
Michael On 21.10.2011, at 23:23, Godmar Back godmar@gmail.com wrote:
Supporting JSON-P would be great; Michael mentioned that BaseX supports it, but a search for JSON-P or 'callback' in the Wiki turns up empty...
What's the callback argument used in JSON-P called? callback?
- Godmar
On Fri, Oct 21, 2011 at 12:51 AM, colin mcenearney colinmcenearney@yahoo.com wrote:
Hi Christian and Michael, and everyone. Thanks for your replies.
I'm still having a little difficulty. Attempting to return results with method=jsonml I still get this error (using jquery's ajax methods):
thrown error: [Exception... "Access to restricted URI denied" code: "1012"
which I think is a result of sending an http-request across different ports.
I think my question might be clearer with some background: My idea for a simple app to learn the db is a blog, where each entry has its own xml file which contains, among other things, chunks of valid xhtml. I was envisioning a very simple interaction where javascript sends a get or post request and the db returns bits of xhtml.
Can this be done without the use of additional server-side scripting? Maybe with direct calls to an xquery file like http://mysite.com/blog/blog.xq?categ=xmldb&level=beginner ?
Colin
From: Christian Grün christian.gruen@gmail.com To: colin mcenearney colinmcenearney@yahoo.com Cc: "basex-talk@mailman.uni-konstanz.de" basex-talk@mailman.uni-konstanz.de Sent: Tuesday, October 18, 2011 11:54 AM Subject: Re: [basex-talk] ajax and http server - cross-domain, jsonp or proxy?
Dear Colin,
thanks for your e-mail.
I'm not really a developer so this might be an obvious question: using basex's http server, what is the best strategy for ajax-style communication between browser and db?
As Michael already pointed out, there is no "unique" strategy how to use BaseX with AJAX. One popular way is to use our new "json" serialization method, which allows you to directly return JSON from BaseX. A small example:
- Start the HTTP server via "basexhttp -l" (the -l flag will
communicate with the local database context; this way, no other socket connection will be used)
- Via REST, retrieve a document or run a query and specify "jsonml"
as output method: http://localhost:8984/rest/database/doc.xml?method=jsonml
This way, the XML result will be directly serialized, using the JSONML syntax. If you have created your XML documents from JSON input files, you may as well use "json" as serialization format. Pleave check out our documentation as well:
http://docs.basex.org/wiki/JSON_Functions
Feel free to ask if this is not exactly what you are looking for. Christian
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
basex-talk@mailman.uni-konstanz.de