Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8070531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:25:08+00:00 2026-06-05T13:25:08+00:00

What is the use of beforeSend Function in jQuery Ajax? How to use the

  • 0

What is the use of beforeSend Function in jQuery Ajax?

How to use the jQuery function?

I am Using jQuery 1.6.0, and Using Jersey API (Restful Web services) on Server Side.

$.ajax({

    type: "GET",
    url:ajax_url,
    dataType: "json",
    contentType: "application/json",                    
    async: false,
    beforeSend: function (xhr){ 
xhr.setRequestHeader('Authorization', "Basic "+ btoa(username + ':' + password)); 
    },
    success:function(data){
        alert(data.groups);
    },
    error:function(xhr,err){
        console.log("readyState:"+xhr.readyState+"\nstatus: "+xhr.status)
        alert(xhr.responseText)
        alert("Service is not Available , Try it after Some time");
    }
});

Java Code :

@GET

@Produces(MediaType.APPLICATION_JSON)

public String authCheck(){

return "({"groups": "success"})";

}

Whenever I am sending for authentication I am getting success response.

How to use beforeSend function and does we need to do any thing on server side?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:25:09+00:00Added an answer on June 5, 2026 at 1:25 pm

    Generally beforeSend() is used to do some stuff before actually send AJAX request like set Custom header and etc…

    but your need is different that you want to authenticate user before your ajax call than

    create one another function which give you User is authenticated or Not in Response
    suppose this function is checkAuth();

    so use

    type: "GET",
        url:ajax_url,
        dataType: "json",
        contentType: "application/json",                    
        async: false,
        beforeSend:checkAuth,
    
    .
    .
    .
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a ajax call using jQuery I'm making use of the following options
I'm developing a web application, where I use jQuery to make Ajax calls to
the problem is whenever I use $.get, $.post or $.ajax, I can't find a
I am using pjax and wanted to use the beforesend call to display a
I'm using buttons to submit data via Ajax. I'm using jQuery to disable and
Just started using AJAX today via JQuery and I am getting nowhere. As an
I am using jQuery to make an AJAX call. The call is procesed and
Whats the best way to hookup AJAX functionality to an existing Form using jQuery
I'm using a jquery to make an $.ajax request. It works fine in chrome/firefox
i have problems with ajax requests and simple <input type=submit/> . i use to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.