2015-02-10 110 views
0

我想將markLogic用作文檔存儲 - 如果有人可以列出簡單的AJAX方法來訪問mL,我會非常高興。 我已經在我的PC上加載了mL - 我的本地主機指向Apache(WAMPserver)。 我從第三方網站(yahoo.com)上傳數據(json & xml),然後按摩它,我想用一個簡單的jQuery AJAX函數以mL爲單位進行存儲。請不要任何第三方軟件,如ROXY等使用jQuery AJAX與marklog進行交互

回答

0

請確保您有REST服務,從Marklogic數據庫獲取數據:

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() { 
 
\t \t $('#submit').button(); 
 
\t \t $("#form").submit(function(e) { 
 
\t \t \t var user = $('#user').val(); 
 
\t \t \t var password = $('#password').val(); 
 
\t \t \t var url = $('#url').val(); 
 
\t \t \t e.preventDefault(); 
 
\t \t \t $.ajax({ 
 
\t \t \t \t type: "POST", 
 
\t \t \t \t url: url, 
 
\t \t \t \t data: $("#form").serialize(), 
 
\t \t \t \t beforeSend: function (xhr) { 
 
\t \t \t \t \t \t xhr.setRequestHeader ("Authorization", "Basic " + btoa(user + ":" + password)); 
 
\t \t \t \t \t }, 
 
\t \t \t \t success: function(data) 
 
\t \t \t \t { 
 
\t \t \t \t \t alert(data); // show response from the php script. 
 
\t \t \t \t }, 
 
\t \t \t \t error: function(data) 
 
\t \t \t \t { 
 
\t \t \t \t \t alert("Error: " + data); 
 
\t \t \t \t } 
 
\t \t \t \t }); 
 
\t \t }); 
 
    }); 
 
</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> \t 
 
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部分。