KOSUNI KOREA
Korean News in English
Technology

Learning the Basics of AJAX with jQuery

Published October 16, 2026 · 1 views
Learning the Basics of AJAX with jQuery

What is AJAX?

You've probably noticed websites updating data without refreshing the page—like when you post a comment or see real-time search results.

Examples include:

  • Commenting

  • Liking a post

  • Real-time search

  • Autocomplete features

  • Chat applications

  • Notification systems

All these functions typically rely on AJAX.

AJAX is a technology that allows data exchange with a server without reloading the entire page.


Why Use AJAX?

In the past, every server request would reload the whole page. With AJAX, only necessary data is fetched.

The benefits include:

  • No screen flickering

  • Faster performance

  • Better user experience

  • Only required data is retrieved

  • Efficient for mobile environments

Most modern web services now use AJAX.


How AJAX Works

AJAX operates in this sequence:

Browser

↓

AJAX Request

↓

Web Server

↓

Data Processing

↓

JSON Response

↓

Screen Update

In short, it fetches only the needed data without refreshing the page.


GET vs. POST

AJAX commonly uses GET and POST methods.

GET

  • Used for data retrieval

  • Data appears in the URL

  • Faster processing

Examples:

  • Loading posts

  • Displaying product lists

  • Search queries


POST

  • Used for saving or modifying data

  • Data isn't visible in the URL

  • Larger data capacity

Examples:

  • User registration

  • Login functionality

  • Comment submission

  • Saving posts


$().get()

The simplest GET method.

$.get(

    "test.php",

    function(data){

        console.log(data);

    }

);

The server response is stored in the 'data' variable.


$().post()

For POST requests.

$.post(

    "login.php",

    {

        userid:"admin",

        password:"1234"

    },

    function(data){

        console.log(data);

    }

);

Commonly used for login features.


$().ajax()

The most widely used method.

$.ajax({

    url:"test.php",

    type:"GET",

    success:function(data){

        console.log(data);

    }

});

This is the standard approach in professional development.


type

Specifies the request method.

type:"GET"

or

type:"POST"


url

The server address to request.

url:"member.php"

Enter API endpoints or PHP files here.


data

Data to send to the server.

data:{

    userid:"hong",

    age:30

}

Written as an object.


success()

Executes when the request succeeds.

success:function(data){

    console.log(data);

}

This is the most commonly used function.


error()

Executes on failure.

error:function(){

    alert("An error occurred.");

}

This should always be included in production code.


complete()

Runs after success or failure, regardless of outcome.

complete:function(){

    console.log("Completed");

}

Frequently used to hide loading indicators.


What is JSON?

AJAX primarily uses JSON data format.

Example:

{

    "name":"Hong Gil-dong",

    "age":30,

    "city":"Seoul"

}

In JavaScript:

console.log(data.name);


JSON Arrays

[

    {

        "name":"Apple"

    },

    {

        "name":"Banana"

    }

]

Output:

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

    console.log(v.name);

});

Practical Example 1: Loading Member List

Fetching a list of members.

$.ajax({

    url:"member.php",

    success:function(data){

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

    }

});

Frequently used in admin panels.


Practical Example 2: Submitting Comments

Posting comments without refreshing the page.

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

    $.ajax({

        url:"comment.php",

        type:"POST",

        data:{

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

        },

        success:function(){

            alert("Submitted!");

        }

    });

});

This is the most common example in forums.


Practical Example 3: Search Autocomplete

Real-time search suggestions as users type.

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

    $.ajax({

        url:"search.php",

        data:{

            keyword:$(this).val()

        },

        success:function(data){

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

        }

    });

});

Commonly seen in search fields.


Practical Example 4: Like Button

Implementing a like button for social media or e-commerce sites.

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

    $.post(

        "like.php",

        {

            id:10

        },

        function(data){

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

        }

    );

});

Widely used in social platforms and shopping sites.


dataType

Specifies response data format.

dataType:"json"

HTML:

dataType:"html"

Text:

dataType:"text"

JSON is the most commonly used format.


beforeSend()

Executes before sending a request.

beforeSend:function(){

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

}

Commonly used to display loading indicators.


complete()

Hides the loading indicator after request completes.

complete:function(){

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

}

Common Beginner Mistakes

Only Using success(), Skipping error()

Without an error handler, debugging becomes difficult when issues arise.

Always include both success() and error().


Mixing Up GET and POST

Use GET for data retrieval (e.g., viewing posts) and POST for actions that modify data (e.g., saving comments).


Treating JSON Strings as Objects

If you receive a JSON string, use JSON.parse() to convert it into an object. However, modern frameworks often handle this automatically.


Practice Exercises

Exercise 1

Use $.get() to fetch data from test.php and display it.


Exercise 2

Submit name and age using $.post().


Exercise 3

Fetch JSON data and display as a list.


Exercise 4

Create an AJAX comment submission feature.


Exercise 5

Build a search autocomplete feature that sends requests as users type.


Key Takeaways

  • AJAX enables data exchange without page reloads.

  • GET for data retrieval, POST for data modification.

  • $().ajax() is the most commonly used AJAX method.

  • Use success(), error(), and complete() together for robust code.

  • JSON is the standard data format in AJAX communication.

  • Understanding data and dataType options allows you to handle most AJAX requests.

  • beforeSend() and complete() are essential for managing loading states.


Conclusion

This tutorial covered the fundamentals of jQuery-based AJAX, including its role in modern web development. By enabling seamless data exchange without page refreshes, AJAX significantly enhances user experience across various applications—from forums and member management to e-commerce platforms.

Key technologies like $().ajax(), $.get(), $.post(), and JSON are essential for building features such as comment systems, member listings, product searches, and admin panels. Mastering these concepts will prepare you for real-world development challenges.

In the next lesson, we'll dive into practical AJAX projects including implementing comment submission, member list retrieval, and product search functionalities directly in a live forum environment.

FAQ

What is AJAX used for?

AJAX enables dynamic content updates without reloading the entire page, improving user experience in web applications.

How does GET differ from POST in AJAX?

GET retrieves data and appears in URLs; POST submits or modifies data without exposing it in the URL.

Korean Source

This article is an English localization of a Korean-language report from BlogScore. Original: [Jquery 강좌] 9강 AJAX 기초 배우기