KOSUNI KOREA
Korean News in English
Technology

AJAX Real-World Project Tutorial for Beginners

Published October 16, 2026 · 1 views
AJAX Real-World Project Tutorial for Beginners

The Project We'll Build

Last time we covered the basic syntax of AJAX.

This session will focus on implementing actual features you'd find in real websites.

In this tutorial, we'll create these functions:

  • Comment submission

  • Loading comment lists

  • User list retrieval

  • Deleting posts

  • Likes button functionality

  • Real-time search

  • Loading indicators

  • JSON data display

These are among the most common AJAX examples used in professional development.


Project Setup

We'll prepare this HTML for our example:

<input type="text" id="comment">

<button id="btnWrite">

Comment Submit

</button>

<ul id="commentList">

</ul>

When the button is clicked, we'll save comments to the server and refresh the list without reloading the page.


Submitting Comments

This is one of the most common AJAX examples.

$("#btnWrite").click(function(){

    $.ajax({

        url:"comment_insert.php",

        type:"POST",

        data:{

            comment:$("#comment").val()

        },

        success:function(){

            alert("Comment submitted successfully.");

        }

    });

});

The entered comment is sent to the server.


Refreshing Comment List After Submission

We need to update both the server and the display immediately after submission.

success:function(){

    loadComment();

}

After posting a comment, we simply call:

loadComment();

to refresh the list.


Loading Comment Lists

function loadComment(){

    $.ajax({

        url:"comment_list.php",

        success:function(data){

            $("#commentList").html(data);

        }

    });

}

The comments update without refreshing the page.


Auto-Loading Comments on Page Load

$(function(){

    loadComment();

});

When the website loads, it automatically displays the latest comments.


Receiving Data in JSON Format

We'll receive comment lists as JSON data:

$.ajax({

    url:"comment.php",

    dataType:"json",

    success:function(data){

        console.log(data);

    }

});

In professional work, JSON is more commonly used than HTML for data transfer.


Displaying JSON Data

For example, if the server sends:

[
    {

        "writer":"Hong Gildong",

        "comment":"Hello"

    },

    {

        "writer":"Kim Chul-su",

        "comment":"Nice to meet you"

    }

]

We can display it like this:

$.each(data,function(i,v){

    $("#commentList").append(

        "<li>"+

        v.writer+

        " : "+

        v.comment+

        "</li>"

    );

});

to show the data in a readable format.


Loading User Lists

This is commonly used in admin pages.

$.ajax({

    url:"member.php",

    dataType:"json",

    success:function(data){

        $.each(data,function(i,v){

            $("#memberList").append(

                "<li>"+

                v.name+

                "</li>"

            );

        });

    }

});


Deleting Posts

Clicking a delete button sends a request to the server.

$(".delete").click(function(){

    var id=$(this).data("id");

    $.ajax({

        url:"delete.php",

        type:"POST",

        data:{

            id:id

        },

        success:function(){

            alert("Deletion complete");

        }

    });

});


Refreshing After Deletion

After deletion completes, we refresh the list:

success:function(){

    loadBoard();

}

This is the most common approach in professional development.


Implementing Like Functionality

This is a popular feature on social media platforms.

$("#likeBtn").click(function(){

    $.ajax({

        url:"like.php",

        type:"POST",

        data:{

            id:10

        },

        success:function(data){

            $("#count").text(data);

        }

    });

});

The like count updates immediately without page refresh.


Real-Time Search

As users type in the search box, the system communicates with the server:

$("#keyword").keyup(function(){

    $.ajax({

        url:"search.php",

        data:{

            keyword:$(this).val()

        },

        success:function(data){

            $("#result").html(data);

        }

    });

});

This is commonly used in shopping sites and portals.


Displaying Loading Indicators

It's helpful to show a loading screen during AJAX requests:

beforeSend:function(){

    $("#loading").show();

}


Hiding the Loading Indicator

complete:function(){

    $("#loading").hide();

}

This significantly improves user experience.


Error Handling

error:function(){

    alert("Server error occurred.");

}

This is highly recommended in professional work.


Displaying Success Messages

success:function(){

    alert("Save completed");

}

Or display it on screen:

$("#msg").text("Saved.");

to provide immediate feedback.


Sending Multiple Data Fields

data:{

    name:$("#name").val(),

    age:$("#age").val(),

    city:$("#city").val()

}

You can send as many fields as needed in object format.


Processing Response Data

For example, if the server responds with:

{

    "result":"success"

}

We can process it like this:

if(data.result=="success"){

    alert("Success");

}else{

    alert("Failure");

}

to handle different response types.


Real-World Example 1

AJAX-based registration form

$("#joinBtn").click(function(){

    $.ajax({

        url:"join.php",

        type:"POST",

        data:$("#joinForm").serialize(),

        success:function(){

            alert("Registration complete");

        }

    });

});

The serialize() method allows easy submission of entire form data.


Real-World Example 2

Displaying product lists

$.ajax({

    url:"product.php",

    dataType:"json",

    success:function(data){

        $.each(data,function(i,v){

            $("#product").append(

                "<li>"+

                v.title+

                "</li>"

            );

        });

    }

});


Real-World Example 3

Loading post content

$.ajax({

    url:"view.php",

    data:{

        id:5

    },

    success:function(data){

        $("#content").html(data);

    }

});

The content updates without navigating to a new page.


Real-World Example 4

Automatic refresh system

setInterval(function(){

    loadComment();

},5000);

This reloads comments every 5 seconds.

This approach is commonly used in chat applications as well.


Common Beginner Mistakes

Not Refreshing the Display After Success

The server may save data, but the display might remain unchanged.

You must either reload the list or directly update the screen.


Forgetting to Specify dataType

When using JSON, it's important to specify:

dataType:"json"

This ensures proper parsing of the response.


Not Using beforeSend

Without this, users won't know when a request is in progress.

Displaying a loading indicator improves user experience significantly.


Practice Exercises

Exercise 1

Implement comment submission using AJAX.


Exercise 2

Retrieve and display user lists using JSON data.


Exercise 3

Create a likes button that updates the count number when clicked.


Exercise 4

Implement real-time search functionality.


Exercise 5

Show a loading indicator during AJAX requests and hide it when complete.


Key Takeaways

  • AJAX allows data exchange without refreshing the page.

  • Comment systems and list updates are classic examples of AJAX implementation.

  • JSON is the most commonly used data format in professional development.

  • In success handlers, it's standard practice to update the display as well as handle server responses.

  • Using beforeSend and complete allows easy implementation of loading indicators.

  • The serialize() method enables sending entire form data with minimal code.

  • AJAX is essential for forums, e-commerce sites, admin panels, and chat systems in modern web development.


Conclusion

In this session, we implemented a real-world AJAX project to explore various features used in actual web services.

Functions like comment submission, user list retrieval, likes, and real-time search all operate using AJAX - making it an essential skill for modern websites.

In the next lesson, we'll learn about practical jQuery functions commonly used in professional development, building on what you've learned to improve development efficiency with various techniques and real-world applications.

FAQ

What is AJAX?

AJAX (Asynchronous JavaScript and XML) allows web pages to update content dynamically without reloading the entire page.

Why use JSON with AJAX?

JSON is a lightweight data format that's easier for both developers and browsers to parse compared to HTML or XML, making it ideal for AJAX communication in professional development.

Korean Source

This article is an English localization of a Korean-language report from BlogScore. Original: [Jquery 강좌] 10강 AJAX 실전 프로젝트