Am using the following bit of code to allow users to add new content (html input fields), and it’s working well.
But, I would like for it to work multiple times, not just once.
Currently, it allows a user to click on Add Item, adds the content, but then won’t work again.
Any ideas? (Am more a PHP person than AJAX/Javascript, but think the latter is probably the route to go).
<script>
function loadDoc(url, cFunction) {
var xhttp;
xhttp=new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
cFunction(this);
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
function myFunction(xhttp) {
document.getElementById("demo").innerHTML =
xhttp.responseText;
}
</script>
<p id="demo">
<label>Add New Content</label>
<button type="button" onclick="loadDoc('content.php', myFunction)">Add Item</button>
</p>