Home Dynamically fetching a web page in a particular div of webpage
Reply: 1

Dynamically fetching a web page in a particular div of webpage

Shipra Chaudhary
1#
Shipra Chaudhary Published in 2018-02-14 08:08:58Z

I have a webpage wherein I want that onclick of a link or buttonn; the content of a particular div of webpage get updated and replaced with the content which I have scripted in other html page. How to do that?

Atik Hashmee
2#
Atik Hashmee Reply to 2018-02-14 08:21:02Z

There are several ways to do that .

<script>
function loaddata()
{ 
var xhr = new XMLHttpRequest();
xhr.open("GET","page.html",true);
xhr.onload = function(){
if(this.readyState === 4)
{ 
var div = document.getElementById("divid"); // the div where you want to load the data 
div.innerHTML = this.responseText;
}
}
xhr.send();
}
</script>

html code

<button onclick="loaddata()">click</button>
<div id="divid"></div>

there are other ways to do that . but i have shown only javascript one hope this helps you what you are looking for

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.300004 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO