🏠 Home / Hub 🏠 Back to Hub

📡 JSON & AJAX

Data Format + Async HTTP | API communication ကို JavaScript နဲ့

01

JSON Basics

Syntax, parse(), stringify(), nested data

02

Fetch API — GET

fetch(), .then(), response.json(), async/await

03

Fetch — POST/PUT/DELETE

method, headers, body, REST CRUD via fetch

04

Async/Await & Errors

try/catch, Promise, error handling patterns

05

XMLHttpRequest (XHR)

Legacy AJAX, readyState, jQuery $.ajax

06

Real API Examples

JSONPlaceholder, GitHub API, display in DOM

Prerequisites: JavaScript (js_01 - js_08) သိဖို့ လိုတယ်
No setup needed: Browser မှာ directly run လို့ ရ — Node.js မလို!
CORS note: API calls ကို local HTML file မှာ browser security block ကောင်း ကောင်း — Live Server နဲ့ run ပါ

⚡ JSON & Fetch Quick Reference

// JSON parse & stringify
const obj  = JSON.parse('{"name":"Ko","age":25}');
const str  = JSON.stringify(obj);   // back to string

// Fetch GET (async/await)
async function getUsers() {
  try {
    const res  = await fetch('https://api.example.com/users');
    const data = await res.json();
    console.log(data);
  } catch (err) {
    console.error('Error:', err);
  }
}

// Fetch POST
await fetch('/api/users', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ name: 'Ko Ko', age: 25 })
});

📌 Study Checklist