Page 192 - CITS - CSA - TP (Volume 1) - Hindi
P. 192

कंप्यूटर सॉफ्टवेयर एप्लीकेशन- CITS



           अ ास 46 : AJAX अनु योग का इ  ीम ट (ि या यन) (Implementing an AJAX application)



            उ े
           इस अ ास के  अंत म  आप यह कर सक  गे
           •  AJAX अनुरोध को ह डल कर
           •  HTML पेज कं ट ट को गितशील  प से अपडेट कर ।


           आव कताएं  (Requirements)
           औजार/साम ी (Tools/Materials)

           •  लेटे  कॉ  फ़गरेशन वाला डे टॉप / लैपटॉप
           •  टे  एिडटर
           •  वेब  ाउज़र
           •  अपाचे वेब सव र

            ि या (Procedure)

           टा  1: AJAX ए  के शन का काया  यन

           I   AJAX अनुरोध को संभालने और साम ी को गितशील  प से अपडेट करने के  िलए एक जावा    फ़ाइल बनाता  ँ।
              1  टे  एिडटर खोल

              2  िन िल खत कोड िलख

                 // Get references to the button and content container
                 const loadButton = document.getElementById(‘loadButton );
                 const contentContainer = document.getElementById(‘contentContainer );

                 // Function to load content asynchronously
                 function loadContent() {
                 // Create a new XMLHttpRequest object

                 const xhr = new XMLHttpRequest();
                 // Define the callback function to handle the response
                 xhr.onreadystatechange = function() {

                 // Check if the request is complete and successful
                 if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {

                 // Update the content container with the response text
                 contentContainer.innerHTML = xhr.responseText;
                 }

                 };
                 // Open a GET request to the desired URL
                 xhr.open(‘GET , ‘example.txt , true);

                 // Send the request
                 xhr.send();



                                                           176
   187   188   189   190   191   192   193   194   195   196   197