Hi guys,
I have a loop like this:
<ul>
<?php foreach($questions as $question) { ?>
<li class=position_relative>
<div class=floatleft>
<?php echo $question['firsttolast']; ?>
</div>
<a href="form.php" class=floatright>Answer</a>
</li>
<?php } ?>
</ul>
I want to attach a form to the corresponding li item if someone click on the link to answer the question with the code below:
var doc = document
, ans = doc.getElementsByClassName('floatright');
for ( var i = 0, j = ans.length; i < j; i += 1 ) {
(function(x) {
ans[x].addEventListener('click', function(e) {
e.preventDefault();
var url = this.getAttribute("href");
var xhr = newXMLHttpRequest();
xhr.open("GET", url, false);
if (xhr.readyState == 4) {
var div = doc.createElement('div');
div.innerHTML = xhr.responseText;
// HOW TO APPEND IT TO THE <LI>?
}
xhr.send();
});
})(i);
}
How do I do it?
I want it be like a thread comment like in facebok (no real time need).
The current practice I use is going to the form page and return when submit.
I want to add ajax to this case.
thank you,