Using Basic Authentication in jQuery and Ajax | HTTP Get Request with Username and Password in JQuery

In order to preemptively send authentication without a 401 Unauthorized response, use 'headers' as given below:

  type: "GET",
  url: "index.htm",
  dataType: 'json',
  async: false,
  headers: {
    "Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD)
  data: '{ "comment" }',
  success: function (){
    alert('Thanks for your comment!'); 

Explain Basic Syntax of jQuery? | jQuery Interview Question | jQuery Tutorial

jQuery syntax structure can be broken down in to four parts:-
  • All Jquery commands start with a “$” sign.
  • Followed by the selection of the HTML element. For example below is a simple image where we are selecting a HTML textbox by id “txt1”.
  • Then followed by the DOT (.) separator. This operator will separate the element and the action on the element.
  • Finally what action you want to perform on the HTML element. For instance in the below Jquery code we are setting the text value to “Hello JQuery’

Firing An Event When The ScrollBar Reaches Webpage Bottom Using jQuery | jQuery Tutorial

The JavaScript code snippet below shows an alert message when the scroll bar hits the bottom of the page. The jquery scroll function will be fired every time we scroll the page. However, we restrict the logic to execute by putting this inside a conditional statement that determines the position of the scroll bar.
  if($(window).scrollTop() == $(document).height() - $(window).height() ){

    alert("reached bottom of the page");