0

当我单击按钮获取日期时间时,没有任何反应。在此之后,我不明白该怎么做。请帮我写代码。

有两个文件:

  1. 索引.html
  2. 日期.jsp

如下

索引.html

<html>
<head>
    <title>JavaScript-Ajax Application</title>

    <script language = "javascript">
    var XMLHttpRequestObject = false;

    if (window.XMLHttpReguest) {
        XMLHttpRequestObject = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
    }

function getDateTime(datetimefile, divID) {
alert(divID)
    if(XMLHttpRequestObject) {
        var obj = document.getElementById(divID);
        XMLHttpRequestObject.open("POST", datetimefile);

        XMLHttpRequestObject.onreadystatechange = function()

        {
        if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
            obj.innerHTML = XMLHttpRequestObject.responseText;
            }
        }

        XMLHttpRequestObject.send(null);

    }
}
</script>
</head>
<body>
    <H1>JavaScript-Ajax Application</H1>
    <form>
    <input type = "button" value = "Get Current Date and Time" onclick="getDateTime('date.jsp', 'targetDiv')">
    </form>
    <div id="targetDiv">
    </div>
</body>
</html>

日期.jsp

<%@Page contentType="text/html" import="java.util.*" %>
<html>
<body>
<p>&nbsp;</p>
<div align="left">
<table border="0" cellpadding="0" cellspacing="0" width="460" bgcolor="ADADDE">
<tr>
<td width="100%"><font color="#000000">AJAX Date</font></td>
</tr>
<td width="100%"><b>&nbsp;Current Date and time is:&nbsp; <font color="#FF0000">
<%= new java.util.Date()%>
</font></b></td>
</tr>
</table>

</div>
</body>
</html>
4

0 回答 0