I am in need of adding a polling mechanism to call a web service from my webpage. To achieve this, I am attempting to utilize an ajax
call within a javascript
page. However, I am fairly new to both ajax
and javascript
. Below is the code snippet that I have written.
<html>
<head>
<script language="JavaScript" type="text/javascript">
function pollServerForNewMail() {
setTimeout(function(){
$.ajax({ url: "server", success: function(data){
alert("TEST");
poll();
}, dataType: "json"});
}, 10000);
</script>
</head>
<body>
</body>
</html>
My goal is to trigger the display of the alert message "TEST" every 10 seconds. Can anyone provide assistance with this task?
I will update the post with my two jsp files.
index.jsp file
<html>
<table style="width:100%;text-align:center;'">
<tr>
<td style="text-align:center;width:100%">
<a href="polling.jsp?reset=true"><img src="images/import.png" /></a>
</td>
</tr>
</table>
</html>
polling.jsp file
<html>
<head>
<script language="JavaScript" type="text/javascript">
function pollServerForNewMail() {
setTimeout(function(){
$.ajax({ url: "server", success: function(data){
alert("TEST");
poll();
}, dataType: "json"});
}, 10000);
}
pollServerForNewMail() ;
</script>
</head>
<body>
</body>
</html>
Thank you