XMLHttpRequest In Hindi

📔 : AJAX 🔗

AJAX request send करने के लिए JavaScript की predefined class XMLHttpRequest का Object बनाना पड़ता है , और लगभग सभी modern browsers इसे support करते हैं। तो AJAX request send करने के लिए यह सबसे पहला step है।


let xhttpreq =  XMLHttpRequest();

XMLHttpRequest Properties

जैसा कि आपने पिछले topics में भी पढ़ा होगा कि JavaScript में आप किसी भी Object को console में print करके सभी properties को आसानी से देख सकते हैं।


<script type="text/javascript">
let xhttpreq = new XMLHttpRequest();
console.log(xhttpreq);
</script>

JS XMLHttpRequest

Image में XMLHttpRequest की सभी properties define की गयी हैं जिनका use कुछ इस तरह से है।

  1. onreadystatechange : इस property को एक method assign किया जाता है, जब भी request की readyState property change होती है , तब वह function run हो जाता है।
  2. readyState : property XMLHttpRequest का status hold करती है।
    • 0 : means request अभी initialize नहीं हुई है।
    • 1 : server से connection establish हो चूका है।
    • 2 : server द्वारा request को receive कर लिया गया है।
    • 3 : request को process किया जा रहा है।
    • 4 - request finish होकर response ready  है।
  3. responseText : यह simply response data को as a string return करती है , request process होने के बाद।
  4. responseXML : यह response data को as a XML format में return करती है।
  5. status : यह request का status number return करती है।
    • 200 : request Ok.
    • 404 : दिया गया URL गलत है या defined नहीं है।
    • 500 : server error .
  6. statusText : यह status text (OK / Not Found ) return करती है।

XMLHttpRequest Methods

  1. send() : इसी method का use करके request send की जाती है।
  2. abort() : यह method current request को cancel  है।
  3. setRequestHeader() : इसका use header information set करने के लिए किया जाता है।
  4. getAllResponseHeaders() : यह request की सभी header information return करता है।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers