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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:04:39+00:00 2026-06-04T17:04:39+00:00

Working XHR request that sends a file with all required request headers set. var

  • 0

Working XHR request that sends a file
with all required request headers set.

var upload = function (file) {
    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/Admin/Upload', true);
    xhr.setRequestHeader('X-Filename', file.name);
    xhr.setRequestHeader('pageid', pageid);
    xhr.setRequestHeader('catid', catid);
    xhr.send(file);
}

Trying to get the below working (Using jQuery 1.7.2)

var xhr = new XMLHttpRequest();

var upload = function (file, xhr) {
    $.ajax
    ({
        url: '/Admin/Upload',
        beforeSend: function (xhr) {
            xhr.setRequestHeader('X-Filename', file.name);
            xhr.setRequestHeader('pageid', pageid);
            xhr.setRequestHeader('catid', catid);

        },
        data: file,
        success: function (data) {

            alert('Load was performed.');
        }

    });
}

Update:
Ok, so I have progressed a bit and the request now actually hits the action method,
however there is no data in the input stream and all the file key arrays are null,
so the actual file data does no appear to be going through. The request headers are coming through fine. The (data: file) is different I presume to xhr.send(file) ?

Now using this:

var upload = function (file) 
{
    $.ajax
    ({
        url: "/Admin/Upload",
        headers: { catid: catid, pageid: pageid },
        processData: false,
        data: file,
        success: function (data) {

            alert('Load was performed.');
        }

    });
}
  • 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-04T17:04:40+00:00Added an answer on June 4, 2026 at 5:04 pm

    Try also set contentType to false and type to 'POST'.

    $.ajax({
        url: "/Admin/Upload",
        type: 'POST',
        headers: { catid: catid, pageid: pageid },
        processData: false,
        contentType: false,
        data: file,
        success: function (data) {
            alert('Load was performed.');
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new in node.js. I am currently working on a file upload
Currently I am working on a ajax-based web application that does some XHR. I
working on xcode I realized that if I create a non-void method, I call
I have problem with xhr open() method. My code follows : var xmlhttp=false; if(!xmlhttp)
I have a very simple test page that uses XHR requests with jQuery's $.getJSON
I have a page. In that page's header i have all of my javascript.
I'm uploading multiple files via XmlHTTPRequest and HTML5. I have the uploading working fine,
I have a button which is sending a get request over XHR to a
(Note: See also the related question Can browsers react to Set-Cookie specified in headers
I'm trying to send a request that requires HTTP Digest authentication. Is Digest possible

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.