我继承了在外部文件中调用 Javascript 以进行链接操作的旧代码。下面是JS函数的片段
function webaction(){
$.ajax({
url:contextpath + '/docheck.html'
// more logic below
可以看出,由于未使用,因此 HDIV 验证失败。我应该如何在 JS 中创建 URL 以符合 HDIV?是否可以在 JS 函数中定义 JSTL 标签以便我可以使用
<c:url>
JS里面?
我继承了在外部文件中调用 Javascript 以进行链接操作的旧代码。下面是JS函数的片段
function webaction(){
$.ajax({
url:contextpath + '/docheck.html'
// more logic below
可以看出,由于未使用,因此 HDIV 验证失败。我应该如何在 JS 中创建 URL 以符合 HDIV?是否可以在 JS 函数中定义 JSTL 标签以便我可以使用
<c:url>
JS里面?
您在此网页上对 HDIV 与 AJAX 的集成示例进行了解释。
总而言之,您必须在服务器端创建所有链接和表单元素,如果它们是在客户端创建的 HDIV 没有任何方法来处理它们。
这是一个纯 JS 的示例:
<body>
<h1>AJAX Example</h1>
<c:url value="/ajax/ajaxTime.html" var="url1" />
<h2><div id="myDiv" data="${url1}">Let AJAX make this call</div></h2>
<button type="button" onclick="loadXMLDoc()">View data time</button>
</body>
<script>
function loadXMLDoc() {
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", document.getElementById("myDiv").getAttribute("data"), true);
xmlhttp.setRequestHeader("X-Requested-With","XMLHttpRequest");
xmlhttp.send();
}
</script>
我希望它有帮助
费尔南多·洛萨诺(HDIV 团队)