Home >Backend Development >PHP Tutorial >How Can I Create a Simple \'Hello World\' AJAX Example with PHP and jQuery?

How Can I Create a Simple \'Hello World\' AJAX Example with PHP and jQuery?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-06 11:02:11734browse

How Can I Create a Simple

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:

  1. Include jQuery Library:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
  2. 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn