我有一个部署在 tomcat 上的 JSP-servlets 应用程序。现在我需要从我的 html 进行 web(Ajax)调用并调用 CQ5 网页(完全在 CQ 实例中运行)。当我点击提交按钮时,它进入了ajax调用的错误方法。这是代码
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://crypto-js.googlecode.com/svn/tags/2.5.4/build/crypto/crypto-min.js"></script>
<script src="/resources/scripts/mysamplecode.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#myAjaxRequestForm").submit(function(e){
e.preventDefault();
});
$("#myButton").click(function(e){
//get the form data and then serialize that
dataString = $("#myAjaxRequestForm").serialize();
var username = 'admin';
var password = 'admin';
var url = 'http://localhost:4502/content/geometrixx/en/products/triangle/jcr:content/par/text_0.infinity.json';
$.ajax({
type: 'GET',
url: 'http://localhost:4502/content/geometrixx/en/products/triangle/jcr:content/par/text_0.infinity.json',
dataType : 'json',
'beforeSend': function(xhr) {
var bytes = Crypto.charenc.Binary.stringToBytes('admin' + ":" + 'admin');
var base64 = Crypto.util.bytesToBase64(bytes);
xhr.setRequestHeader("Authorization", "Basic " + base64); //May need to use "Authorization" instead
},
error : function() {
alert('errro');
},
sucess: function(result) {
alert('done');
}
});
});
});
</script>
<div id="allContent">
<div id="myExample">
<form id="myAjaxRequestForm">
<h1> Please enter the Order Information -</h1>
<label for="orderId">Order Id:</label>
<input id="orderId" name="orderId" type="text"><br/>
<br/>
<label for="zipCode">ZIP Code:</label>
<input id="zipCode" name="zipCode" type="text"><br/>
<br/>
<input id="myButton" type="button" value="Submit">
</form>
</div>
<div id="ajaxResponse">
</div>
</div>
</head></html>