Learn how to make requests using XMLHttpRequests

summary of key XMLHttpRequest commands covered in this article
summary of key XMLHttpRequest commands covered in this article
Image source: Author

What Is XMLHttpRequest (XHR)?

  • XMLHttpRequest is an in-built JavaScript object that is used to transfer data between a server and a client without refreshing the whole page.
  • Bu using XHR we can update the page based on the user action.
  • For example, an infinite news feed. (Once the user scrolls down to the end of the page, we make a request to fetch the next article and append the data to the page).
  • Using XHR, we can make both synchronous and asynchronous requests.

Steps to Make a Request Using XMLHttpRequest

  • Create an XMLHttpRequest object.
  • Configure the object with request details .
  • Send request.

1. Create a XMLHttpRequest object

let request = new XMLHttpRequest();

2. Configure the object with request details


Image for post
Image for post
Photo by Deva Darshan on Unsplash

Checking if a primitive value present in an array

  • indexOf
  • includes
  • Using normal For loop
var num = [1,2,3,4,5];

indexOf

num.indexOf(3); // 2num.indexOf(6); //-1num.indexOf('3'); // -1
var array = [NaN];array.indexOf(NaN); // -1


Image for post
Image for post
Image by Vladislav

https://paypal.me/jagathishSaravanan?locale.x=en_GB

About

Javascript Jeep🚙💨

Articles related to javascript javascriptjeep.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store