AJAX Script - Now need to update more than one
I have a results table that allows users to delete library books from
their list of selected books at the checkout stage. I've implemented a
simple AJAX technique so that when the user clicks the Delete button next
to a book in the list it removes it from the page without having to reload
the page - this is all working well.
I now also need to update another element on the page that handles the
pagination showing how many selected books they have. At the top of the
list there is this pagination summary:
<div class="recordlist_nav">Displaying records 1 - 10 of 10 records
selected</div>
As well as removing the book from the list I also need to update this, for
example if they deleted one book it should change to:
<div class="recordlist_nav">Displaying records 1 - 9 of 9 records
selected</div>
I can generate the updated string but not sure how I get my AJAX script to
update multiple elements at the same time. Here's my script:
<script type="text/javascript">
function deleteRecord(recid,articleID) {
// Allocate an XMLHttpRequest object
if (window.XMLHttpRequest) {
// IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp=new XMLHttpRequest();
} else {
// IE6, IE5
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
// Set up the readyState change event handler
xmlhttp.onreadystatechange = function() {
if ((this.readyState == 4) && (this.status == 200)) {
document.getElementById("selectedRecord" +
recid).innerHTML=xmlhttp.responseText;
}
}
// Open an asynchronous POST connection and send request
xmlhttp.open("POST", "delete_record.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("recid="+recid+"&articleID="+articleID);
return false; // Do not follow hyperlink
}
</script>
At present the delete_record.php simply echoes out an empty string when it
deletes the selected record:
$result = '';
echo $result ;
I'm storing the updated pagination header in a $navigation variable. I now
need to pass this back to the script and have that script replace the
contents of the with the contents of the $navigation variable.
No comments:
Post a Comment