On my JSP page, I need to get the data from the XML HTTP request,
here is my code,,
<body>
<div id="ptab">
<button onclick="next()"></button>
</div>
<script>
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","url",false);
xmlhttp.send(null);
document.getElementById("ptab").innerHTML=xmlhttp.responseText;
</script>
<script>
function next(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("ptab").innerHTML = this.responseText;
}
};
xhttp.open("GET", 'url?id=2', true);
xhttp.send();
}
</script>
</body>
when I click the button, it displays the data getting from the URL but it didn't update the URL with id '2'.
firstly, when the page loads, I have to display the data from the URL. when I click the button, I need to display the data from URL?id='2'
how can I get this,
or any other approaches to fetch the response without refreshing the page