Basic PHP and AJAX
Question:
Colin, a self-taught developer, seeks assistance with implementing AJAX in a PHP system. He has encountered difficulties with existing scripts and requests a working "hello world" example to establish baseline functionality.
Answer:
Utilizing jQuery alongside AJAX can significantly simplify the process. Below are the steps involved:
PHP Page (hello.php):
<?php echo "Hello World"; ?>
Main HTML Page:
Include jQuery Library:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
AJAX Call:
<script type="text/javascript"> $(function(){ $.get("hello.php", function(data){ alert(data); }); }); </script>
This simplified example demonstrates a basic AJAX setup to retrieve and display the string "Hello World" using jQuery's GET request.
The above is the detailed content of How Can I Create a Simple \'Hello World\' AJAX Example with PHP and jQuery?. For more information, please follow other related articles on the PHP Chinese website!