我想将markLogic用作文档存储 - 如果有人可以列出一个简单的AJAX方法来访问mL,我会很高兴。 我已经在我的PC上加载了mL - 我的localhost指向Apache(WAMPserver)。 我正在从第三方网站(yahoo.com)上传数据(json& xml),在按摩之后,我想使用简单的jquery AJAX函数将其存储在mL中。请不要像ROXY等第三方s / w
答案 0 :(得分:5)
首先需要为数据库引导REST服务器。从这里开始:
http://developer.marklogic.com/learn/rest/setup#create-a-rest-api-instance
然后你可以跳到关于CRUD的部分。
答案 1 :(得分:0)
确保您拥有从Marklogic数据库获取数据的REST服务:
curl --basic --user admin:none -i -X POST -H "Content-type: application/x-www-form-urlencoded" --data-urlencode module=/ext/invoke/test.xqy --data-urlencode vars='{"j":{"name":"John","bankAccounts":["Northern Bank","Fargo"]}}' http://ec2-18-217-208-58.us-east-2.compute.amazonaws.com:8003/LATEST/invoke
以下是我的index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<title>Marklogic Ajax Test</title>
<meta name="description" content="Marklogic AJAX Test Client" />
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript" >
$(function() {
$('#submit').button();
$("#form").submit(function(e) {
var user = $('#user').val();
var password = $('#password').val();
var url = $('#url').val();
e.preventDefault();
$.ajax({
type: "POST",
url: url,
data: $("#form").serialize(),
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + btoa(user + ":" + password));
},
success: function(data)
{
alert(data); // show response from the php script.
},
error: function(data)
{
alert("Error: " + data);
}
});
});
});
</script>
</head>
<body>
Enter URL of REST service: <input type="text" name="url" value="http://ec2-13-58-46-47.us-east-2.compute.amazonaws.com/marklogic/LATEST/invoke " id="url" style='width:70em' /> <br/>
Username: <input type="text" name="username" value="admin" id="user"/> <br/>
Password: <input type="password" name="password" value="none" id="password"/> <br/>
<h1>Invoke REST service</h1>
<form id="form" method="post" enctype="application/x-www-form-urlencoded">
URI of xquery in module database: <input type="text" name="module" value="/ext/invoke/test.xqy"style='width:70em' ><br>
JSON input: <input type="text" name="vars" value='{"j":{"name":"John","bankAccounts":["Northern Bank","Fargo"]}}' style='width:70em'/> <br/>
<input id="submit" type="submit" value="invoke xquery">
</form>
</body>
</html>
添加到您的/etc/httpd/conf/httpd.conf:
ProxyPass /marklogic/ http://localhost:8003/
<Location /marklogic/>
ProxyPassReverse /
#ProxyHTMLEnable On
SetOutputFilter INFLATE;proxy-html;DEFLATE
#ProxyHTMLURLMap http://localhost:8003/ /marklogic/
#ProxyHTMLURLMap / /marklogic/
</Location>
代码已经过测试,但我没有给你有效的密码。您可能需要修改ProxyPass部分。