Home >Backend Development >PHP Tutorial >How Can I Create a Simple AJAX \'Hello World\' Example with PHP and jQuery?
AJAX with PHP: A Basic Demonstration
Colin, a self-taught PHP developer, encountered challenges in implementing AJAX for real-time page updates. After unsuccessful attempts using self-made scripts and example code from the internet, he seeks a proven functional example for a basic "hello world" demonstration.
Solution
Utilizing jQuery, Colin can simplify the AJAX implementation process. Here's a straightforward example:
echo "Hello World";
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script type="text/javascript"> $(function() { $.get("hello.php", function(data) { alert(data); }); }); </script>
Upon page load, the jQuery code will send an HTTP GET request to hello.php, and the server's response ("Hello World") will be displayed in an alert box. This demonstrates the basic principle of AJAX for dynamic content updates.
The above is the detailed content of How Can I Create a Simple AJAX \'Hello World\' Example with PHP and jQuery?. For more information, please follow other related articles on the PHP Chinese website!