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

  • SEARCH
  • Home
  • 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 9078451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:37:34+00:00 2026-06-16T19:37:34+00:00

New to XMLHttpRequest, and here is some confusion for me: Why must we set

  • 0

New to XMLHttpRequest, and here is some confusion for me:

  1. Why must we set the content type when using the post method in a xmlhttprequest?

    XHR.setRequestHeader(“Content-type”, “application/x-www-form-urlencoded”);

  2. Isnt the default value application/x-www-form-urlencoded already?

  • 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-16T19:37:35+00:00Added an answer on June 16, 2026 at 7:37 pm

    Why must we set the content type when using the post method in a xmlhttprequest?

    XHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    

    HTTP/POST does not ask for that specific content-type when you do a HTTP/POST over AJAX (or for that matter via other means). It is up to you (and up to the server side program handling it). Read the second section for Why we must set it explicitly.

    Very often, we serialise the form (percentile-encode it — a=b&c=d format) and send it across to the server. This format is application/x-www-form-urlencoded. If you are sending an XML, you would use application/xml, for JSON you would use application/json and so on.

    As for GET request, there’s no body and hence we dont really need the content-type header.

    Isnt the default value application/x-www-form-urlencoded already?

    I tried skimming through here for the default content-type header. I couldn’t find anything. However, when I tried doing a HTTP/POST AJAX request via chrome’s console, I noticed that chrome’s default is application/xml.

    Just a piece of advice — never rely on default behaviour except when its explicitly stated and/or is a part of the standard. Why not set the content type explicitly?

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

Sidebar

Related Questions

currently i using this code in phonegap application var xmlhttp = new XMLHttpRequest(); xmlhttp.open(GET,http://192.168.1.19:8080/searchMobile?categoryRequest=true,
I'm trying to write an XMLHttpRequest using the POST method. I have managed to
New developer here,Im using the Custom Image Picker by ray wenderlich. But what I
PREFACE: I'm new to JavaScript and working through some tutorials, and I'm stuck here!
Here's my script: var Ajax = { init: function(){ try{ this.xmlHttp = new XMLHttpRequest();
I am using a codeigniter application that dynamically generates some html elements based on
I am quite new to Phonegap.Iam doing an application in phonegap,here I want to
new on ruby and using windows xp and rails 3, i want to send
new here and new to jQuery. I've searched for an answer to my question/
New programmer here, I am trying to understand and break down this code below

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.