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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:23:42+00:00 2026-05-13T15:23:42+00:00

My question is: can we use dojo.xhrPost to post some Json data? More detail:

  • 0

My question is: can we use dojo.xhrPost to post some Json data? More detail:

I have been experimenting with Dojo code to POST JSON data to a RESTful service. It seems to be that the behaviours of dojo.xhrPost and dojo.rawXhrPost are different, or to be more accurate rawXhrPost() works and xhrPost() does not. This is not consistent with my reading of the docs

The original purpose of
dojo.rawXhrPost was a method that
could be used to send a raw post body
to the server. As of 1.3, this
function is common with
dojo.xhrPost(). So, for usage of
dojo.rawXhrPost(), see dojo.xhrPost()

Which implies that xhrPost() is enough. My code looks like this – I’ve got a “toy” library service that manages Editions of Books. The code wants to POST a new entry,

        var myEdition = {"Edition":{"isbn":"44"}};

        var xhrArgs = {
            url: "http://localhost:8081/LibraryWink/library/editions",
            postData: dojo.toJson(myEdition),
            handleAs: "json",
            headers: { "Content-Type": "application/json"},

            load: function(data) {
                dojo.byId("mainMessageText").innerHTML = "Message posted.";
            },
            error: function(error) {

                dojo.byId("mainMessageText").innerHTML = "Error :" + error;
            }
        };

        var deferred = dojo.rawXhrPost(xhrArgs);

The headers: { “Content-Type”: “application/json”} part in necessary so that my JAX-RC service understands that the content is JSON.

What I find is that the code above works perfectly. However if instead I say:

var deferred = dojo.xhrPost(xhrArgs);

No data is transmitted in the POST. I have a TCP/IP monitor in place and can see that there is nothing transmitted.

So, is this a bug, or am I driving xhrPost() incorrectly? Or should I use rawXhrPost()? If the latter, under what circumstances do we use the two flavours of XhrPost?

  • 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-05-13T15:23:43+00:00Added an answer on May 13, 2026 at 3:23 pm

    As of DOJO 1.4 the this should work:

    var myEdition = {"Edition":{"isbn":"44"}};
    
    var xhrArgs = {
        url: "http://localhost:8081/LibraryWink/library/editions",
        postData: dojo.toJson(myEdition),
        handleAs: "json",
        headers: { "Content-Type": "application/json"},
        load: function(data) {
            dojo.byId("mainMessageText").innerHTML = "Message posted.";
        },
        error: function(error) {
    
            dojo.byId("mainMessageText").innerHTML = "Error :" + error;
        }
    };
    
    dojo.xhrPost(xhrArgs);
    

    If you are posting JSON data, the Content-Type header is critical. If you don’t add it, the browser will default to ‘application/x-www-form-urlencoded’ and URL encode your data for you.

    You may want to add a charset to the Content-Type header (I do this) but that does not stop it from functioning:

        headers: { "Content-Type": "application/json; charset=utf-8"}
    

    On Firefox 3.6 at least, the charset is automatically added.

    As Dom mentions, the HTTP PUT equivalent is dojo.xhrPut. The difference here is that you need to add your request body data as putData instead of postData.

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

Sidebar

Related Questions

I have a question that can I use AS400ConnectionPool in Spring if then pls
Have a rather simple question. Does anyone knows if i can use jparallax both
I need a little question.How can I repair that code so I can use
Brief question What command can I use to make my DataSet refresh it's connection
HTML Javascript question to get the selected value of a input-select I can use
I'd like to use the html5 widget + it's api (http://developers.soundcloud.com/docs/html5-widget) My question: can
Well, question is in title. Is it possible at all? I can use css
I asked a question earlier about why left joins in Linq can't use defined
My question is, why I can not use hide() & show() to hide/show table
I ask a similar question here and Darin Dimitrov answer that we can't use

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.