Notice
Recent Posts
Recent Comments
ยซ   2024/12   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Archives
Today
In Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

A Joyful AI Research Journey๐ŸŒณ๐Ÿ˜Š

[10] 230613 ํŒ€ ํ”„๋กœ์ ํŠธ (3) 10์ผ ์ฐจ) Ajax ์ฝ”๋“œ ๋ฐ ๋งํฌ ๊ธ€๋“ค ๋ณธ๋ฌธ

๐Ÿ’–My Bootcamp Projects Logsโœจ/Team Project 3๏ธโƒฃ

[10] 230613 ํŒ€ ํ”„๋กœ์ ํŠธ (3) 10์ผ ์ฐจ) Ajax ์ฝ”๋“œ ๋ฐ ๋งํฌ ๊ธ€๋“ค

yjyuwisely 2023. 6. 13. 16:34

The Java code you have implemented handles the server-side logic, such as updating the 'visible' column in the MySQL database when the button is clicked. 
The JavaScript code, on the other hand, handles the client-side behavior, which is updating the button text dynamically
without reloading the page. 

When the button is clicked, the JavaScript code will execute in the browser, and you can make an asynchronous request to the server-side Java code using AJAX or fetch API to update the database. 
Once the response is received, you can then update the button text in the browser using JavaScript.

<button id="toggleButton" data-itemname="actualitemname" data-visibility="Y">Stop using</button>

<script>
  var toggleButton = document.getElementById("toggleButton");

  toggleButton.addEventListener("click", function() {
    var itemName = toggleButton.getAttribute("data-itemname");
    var visibility = toggleButton.getAttribute("data-visibility");
    
    // Make an AJAX request to update the column value in MySQL
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "/itemDetails/" + itemName + "/toggleVisibility", true);
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhr.onreadystatechange = function() {
      if (xhr.readyState === 4 && xhr.status === 200) {
        // Update the button's text and visibility attribute based on the response
        if (visibility === "Y") {
          toggleButton.textContent = "Start using";
          toggleButton.setAttribute("data-visibility", "N");
        } else {
          toggleButton.textContent = "Stop using";
          toggleButton.setAttribute("data-visibility", "Y");
        }
      }
    };
    xhr.send();
  });
</script>
<script>
    var button = document.getElementById('toggleButton');

    button.addEventListener('click', function() {
        if (button.innerText === '์‚ฌ์šฉ ์ค‘์ง€') {
            button.innerText = '์žฌ์‚ฌ์šฉ';
        } else {
            button.innerText = '์‚ฌ์šฉ ์ค‘์ง€';
        }

        // Call the toggleVisibility function passing the name as a parameter
        toggleVisibility('${itemDetails.name}');
    });

    function toggleVisibility(name) {
        // Perform the necessary actions to update the visibility status in the database
        // You can use AJAX or make a form submission to your controller endpoint to handle the update

        // Example AJAX code
        // You need to adjust this code according to your backend setup
        $.ajax({
            url: '/itemDetails/' + name + '/toggleVisibility',
            type: 'POST',
            success: function(response) {
                // Handle the success response if needed
                console.log(response);
            },
            error: function(xhr, status, error) {
                // Handle the error response if needed
                console.log(xhr.responseText);
            }
        });
    }
</script>
function toggleVisibility(name) {
    // Make an AJAX request to update the data in the database
    // You can use libraries like jQuery or fetch API to make the AJAX request
    
    // Example using jQuery AJAX
    $.ajax({
        url: '/itemDetails/' + name + '/toggleVisibility',
        type: 'POST',
        success: function(response) {
            // Handle the success response
            // For example, you can update the button text or perform any other necessary actions
            console.log('Data updated successfully');
        },
        error: function(xhr, status, error) {
            // Handle the error response
            console.log('Error updating data:', error);
        }
    });
}

 

ajax๋ฅผ ์‚ฌ์šฉํ•ด ์„œ๋ฒ„์— ๋ฐ์ดํ„ฐ ์ €์žฅํ•˜๋Š” ๋ฐฉ๋ฒ•

์„œ๋ฒ„์™€ ํ†ต์‹ ํ•˜๊ธฐ ์œ„ํ•ด ๋™๊ธฐ์‹ ๋˜๋Š” ๋น„๋™๊ธฐ์‹ ๋ฐฉ๋ฒ•์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ฌด๋ž˜๋„ ๋น„๋™๊ธฐ์‹ ๋ฐฉ๋ฒ•์€ ์„œ๋ฒ„์— ๋ถ€ํ•˜๋ฅผ ๋œ์–ด์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ์œ ์šฉํ•œ๋ฐ์š”... ์ œ ๋ธ”๋กœ๊ทธ์˜ ๊ฒฝ์šฐ ํฌ์ŠคํŒ…์„ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜ ๋“ฑ๋ก์‹œ

webisfree.com


https://terianp.tistory.com/95

 

๋ฐ์ดํ„ฐ ์ „๋‹ฌ์˜ ๊ฝƒ AJAX ๋‹ค๋ฃจ๊ธฐ - JS, JQuery, jsp(feat. ์‹ค์‹œ๊ฐ„ ์•„์ด๋”” ์ค‘๋ณต๊ฒ€์‚ฌ)

์‚ฌ์‹ค ajax ๋ฅผ ๋ช‡๋ฒˆ์ธ๊ฐ€ ์‚ฌ์šฉํ–ˆ๋Š”๋ฐ ์ด์— ๋Œ€ํ•œ ์ •๋ฆฌ๊ฐ€ ํ•˜๋‚˜๋„ ์—†๋‹ค๋Š”๊ฑธ ๊นจ๋‹ฌ์•„์„œ ๋งˆ์Œ๋จน๊ณ  ์ •๋ฆฌํ•ด๋ดค์Šต๋‹ˆ๋‹ค. ์ˆœ์„œ์ƒ JQuery ๋ฅผ ๋จผ์ € ์ •๋ฆฌํ•˜๊ณ  ์ •๋ฆฌํ•ด์•ผํ•˜๋Š”๋ฐ jquery ๋Š” ๋‹ค์Œ ๊ธ€๋ถ€ํ„ฐ ์ •๋ฆฌํ•ด์•ผํ• ๋“ฏใ… ใ… 

terianp.tistory.com


https://azderica.github.io/00-javascript-ajax/

 

[JavaScript] Ajax ์ •๋ฆฌ - Azderica

Javascript Ajax ์›น ๊ฐœ๋ฐœ์„ ํ•˜๋‹ค๋ณด๋ฉด, Ajax๋ฅผ ์•ˆ์“ธ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋‹ค๋งŒ Ajax๋ฅผ ์‚ฌ์šฉํ•ด๋„ ์ •์ž‘ Ajax์— ๋Œ€ํ•ด ๊ณต๋ถ€ํ•ด ๋ณธ์ ์€ ์—†์–ด์„œ ๊ธ€์„ ์ •๋ฆฌํ•ฉ๋‹ˆ๋‹ค. AJAX๋ž€. Ajax๋Š” Asynchronous Javascript and Xml์˜ ์•ฝ์ž์ž…๋‹ˆ๋‹ค. ์ด๋Š”

azderica.github.io

https://devyj.tistory.com/1

 

Ajax ๋ž€?

Ajax (Asynchronous JavaScript and XML) ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ด์šฉํ•ด์„œ ๋น„๋™๊ธฐ์‹์œผ๋กœ XML์„ ์ด์šฉํ•˜์—ฌ ์„œ๋ฒ„์™€ ํ†ต์‹ ํ•˜๋Š” ๋ฐฉ์‹ ์ตœ๊ทผ์—๋Š” XML ๋ณด๋‹ค JSON์„ ๋” ๋งŽ์ด ์‚ฌ์šฉํ•œ๋‹ค. ๋น„๋™๊ธฐ์‹์ด๋ž€ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ผ์ด ๋™์‹œ์ ์œผ๋กœ

devyj.tistory.com

https://hei-jayden.tistory.com/248

 

[Ajax] Oracle DB๋กœ๋ถ€ํ„ฐ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์™€์„œ ์ถœ๋ ฅํ•˜๊ธฐ

๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ํŽ˜์ด์ง€ ajax.jsp webapp/ajax.jsp

hei-jayden.tistory.com


 

[62] 230328 Spring: ๋กœ๊ทธ์ธ ํ›„ ๊ฒŒ์‹œํŒ ๋ชฉ๋ก ๋ณด๊ธฐ, ํšŒ์› ๊ฐ€์ž… ํ›„ MySQL DB์— ์ถ”๊ฐ€ํ•˜๊ธฐ [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹

230328 Tue 62nd class Ch. 18 MVC ํŒจํ„ด ๊ตฌํ˜„ ์ง„๋„: Ch. 18 MVC ํŒจํ„ด ๊ตฌํ˜„์— ๊ธฐ๋ฐ˜ํ•œ ์ž์ฒด ์ˆ˜์—… (๊ต์žฌ: ์ตœ๋ฒ”๊ท ์˜ JSP 2.3 ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ: ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์ค‘๊ธ‰๊นŒ์ง€, ์ €์ž: ์ตœ๋ฒ”๊ท ) ์ฑ… ์˜ˆ์ œ ์ฝ”๋“œ: https://github.com/madvirus/jsp23

yjyuwisely.tistory.com

 

[71] 230410 ๋™๊ธฐ์‹, ๋น„๋™๊ธฐ์‹, AJAX, Spring: ๊ฒŒ์‹œํŒ ๋Œ“๊ธ€ [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 71์ผ]

2304010 Mon 71st class ์ฐธ๊ณ : ๋™๊ธฐ์‹ vs ๋น„๋™๊ธฐ์‹ https://dev-coco.tistory.com/46 https://sudo-minz.tistory.com/21 ์ฐธ๊ณ : ajax https://azderica.github.io/00-javascript-ajax/ ์›น ๋ธŒ๋ผ์šฐ์ € → controller → .jsp(ํ•ด๋‹น ํ™”๋ฉด์œผ๋กœ ์ด๋™) ๋™

yjyuwisely.tistory.com

 

728x90
๋ฐ˜์‘ํ˜•
Comments