Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload div with only javascript without jquery

Tags:

javascript

With jQuery I can update the contents of a div I using $.load(). How can I update a div in pure JavaScript?

like image 300
user2463374 Avatar asked Jun 07 '13 14:06

user2463374


1 Answers

As suggested by Julian H. Lam:

var req = new XMLHttpRequest();
req.open("POST", "address_for_div_content", true);
req.onreadystatechange = function () {
  if (req.readyState != 4 || req.status != 200) return;
  document.getElementById('id_of_div')=req.responseText;
};

Here the documentation for XMLHttpRequest

like image 106
Jacopofar Avatar answered Oct 29 '22 20:10

Jacopofar