Does anyone have a simple example for reading Data with JavaScript/JQuery from a Marklogic database?
1 Answers
In a nutshell, there are a few things you may want to do as a quick POC: - search for documents (return search results) - get a document (or documents)
Of course, you may want to do more, but the above gets you started.
I would start with this documentation - and follow the two main links. 1 will give you the actual endpoints and the other will be the developer's guide which dives in (with examples).
https://developer.marklogic.com/try/rest/index
In all cases, you are hitting HTTP resources just like any other HTTP resource, so take this tiny example:
A word query on the full DB for documents containing water: http://localhost:8000/LATEST/search?q=water
The following two samples are refactured from this post: HTTP GET request in JavaScript?
Async Javascript:
function httpGetAsync(theUrl, callback)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
httpGetAsync("http://localhost:8000/LATEST/search?q=water", function(d){window.alert(d)});
jQuery:
$.get(
"http://localhost:8000/LATEST/search",
{q : "water"},
function(data) {
alert('page content: ' + data);
} );
If you want more guidance on specific features of MarkLogic and REST, including transforming documents, etc, post more specific requirements and we can expand on the above. If you do not have specifics, at lest give a few problem statements so that we can help point you in the right direction. There are many, many endpoints - knowing the general idea of your use-cases will help us narrow the field a bit for you.

- 1
- 1

- 7,560
- 12
- 20