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 8631269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:11:46+00:00 2026-06-12T09:11:46+00:00

I have been seeing some examples of the beforeSend callback function. These examples use

  • 0

I have been seeing some examples of the beforeSend callback function.
These examples use sometimes an input parameter: beforeSend:function(req) or beforeSend:function(xhr).

I suppose that this parameter is the XMLHTTPRequest of the jquery request, but when I try these examples it seems that the xhr or the req objects are null.

Is it necessary to create the xhr parameter and initialize it before calling the execution of the jquery object?

Here is the query that I am trying:

function make_basic_auth(un, pss)
{
  var tok = un + ':' + pss;
  var hash = Base64.encode(tok);
  return "Basic " + hash;
}

$('#loginform').submit(function()
{
    $.ajax
    (
        {
            type: 'POST',
            url: 'my.ip.address',
            beforeSend: function(jqXHR, settings)
            {   
                var username = $('.username').val();
                var password = $('.passcode').val();
                var auth = make_basic_auth(username, password);

                jqXHR.setRequestHeader("Authorization",  auth);
                jqXHR.setRequestHeader('Content-Type', 'text/plain');
            },
            success: function (){
               alert("ok");
            },
            error: function (){
               alert("no");
            }
        }
    );
});
  • 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-12T09:11:47+00:00Added an answer on June 12, 2026 at 9:11 am

    Checkout the following code:

    $.ajax({
      url: "google.com",
        beforeSend: function(jqXHR, settings) {
            jqXHR.error = function(){
                alert("failed");
            }
        }
    })​
    

    Working example: http://jsfiddle.net/kXerD/

    Here, I am saying that before sending the request, add a error handler to this request. JQuery provides the objects of jqXHR and settings that is relevant for this request. We don’t need to initialize them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been seeing this in some PHP script: [a-zA-Z0-9_]++ What does the double
Can some other Android developers please confirm or deny what I have been seeing
I have been working with some complex PDF outputs with reportlab. These are generally
I have been seeing this a lot lately and I am unable to find
I have been seeing code like this usually in the start of header files:
Q1: Is there something like too much ajax?? Explanation: I have been seeing programmers
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I am new to python and have been working through the examples in Swaroop
I think I'm suffering from some classpath blues here. I've been following the examples
I've been doing some reading into designing template code have a question about it.

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.