In this guide, we'll explore the process of dynamically changing the content of a DIV element using Ajax, PHP, and jQuery.
When a user clicks on a link, the script makes an Ajax call using the link's URL as a data parameter to your PHP file. The PHP file then processes the data and returns it as a string. Finally, the string is used to replace the content of the targeted DIV.
To implement this functionality, follow these steps:
<script> function getSummary(id) { $.ajax({ type: "GET", url: 'Your URL', data: "id=" + id, // appears as $_GET['id'] on the server-side success: function(data) { // data is your summary $('#summary').html(data); } }); } </script>
Next, add an onclick event to your list items:
<a onclick="getSummary('1')">View Text</a> <div id="summary">This text will be replaced when the onclick event is triggered.</div>
By following these steps, you can dynamically update the contents of a DIV with data retrieved from your PHP file using Ajax and jQuery's manipulation capabilities.
The above is the detailed content of How to Dynamically Update DIV Content Using Ajax, PHP, and jQuery?. For more information, please follow other related articles on the PHP Chinese website!