Hi,
i have one jsp page that will generate and print random number. i called that page using ajax. in calling page if i click a link it will call ajax coding. but the responseText is not changing while i click that link until i close the page and reload though i refresh the page. it prints the same number which i got in first ajax call. how to resolve the problem. this is my code
i have one jsp page that will generate and print random number. i called that page using ajax. in calling page if i click a link it will call ajax coding. but the responseText is not changing while i click that link until i close the page and reload though i refresh the page. it prints the same number which i got in first ajax call. how to resolve the problem. this is my code
Code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="WEB-INF/c.tld" prefix="c" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
var xh;
function greet() {
if(window.XMLHttpRequest) {
xh = new XMLHttpRequest();
} else {
xh = new ActiveXObject("Microsoft.XMLHTTP");
}
xh.onreadystatechange = function() {
var result = xh.responseText;
document.getElementById('greet').innerHTML = result;
}
xh.open("GET","testjsp.jsp",true);
xh.send();
}
</script>
</head>
<body>
<div id='greet'>Greet</div>
<a href="javascript:greet()">Click</a>
</body>
</html>
And here is my JSP page, testjsp.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%int x = (int) (Math.random() *10); %>
<%System.out.println(x); %>
<%=x %>
<%//test.TestPS()%>
</body>
</html>
Comment