<?php
// admin/test-ajax.php
?>
<!DOCTYPE html>
<html>
<head>
    <title>Test AJAX</title>
</head>
<body>
    <button onclick="testAjax()">Test AJAX</button>
    <div id="result"></div>
    
    <script>
    function testAjax() {
        var formData = new FormData();
        formData.append('id', 1);
        
        fetch('delete-category-ajax.php', {
            method: 'POST',
            body: formData
        })
        .then(response => {
            // Check if response is JSON
            var contentType = response.headers.get('content-type');
            if (contentType && contentType.includes('application/json')) {
                return response.json();
            } else {
                return response.text().then(text => {
                    throw new Error('Expected JSON but got: ' + text.substring(0, 100));
                });
            }
        })
        .then(data => {
            document.getElementById('result').innerHTML = 'Success: ' + JSON.stringify(data);
        })
        .catch(error => {
            document.getElementById('result').innerHTML = 'Error: ' + error.message;
        });
    }
    </script>
</body>
</html>