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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:13:29+00:00 2026-05-28T00:13:29+00:00

For a webapp with a RESTful backend I am posting some json to the

  • 0

For a webapp with a RESTful backend I am posting some json to the server using jquery’s $post. Now to my surprise, the json is stuffed in a parameter key for the request’s form data, instead of in the request body. I can think of some other ways to do it, but the question is why it doesn’t work as I expect.

On the server I use scalatra and print some request info:

println("Request received:")
println(fromInputStream(request.getInputStream).getLines().mkString)
println("--------------")
println(request.getParameterMap.toString)
println("==============")

Now a simple curl that does what I think is right:

curl -X POST http://localhost:8080/x -H "Content-Type: application/json" -d '{"a":"b"}'

Produces:

Request received:
{"a":"b"}
-------------
{}
==============

And the bit of html+js to illustrate the problem:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<body>
  <button type="button" onclick="doPost()">
    POST
  </button>
  <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
  <script type="text/javascript">
function doPost() {
    $.post("http://localhost:8080/x",     
           JSON.stringify({"a":"b"} ), 
           function(data) {});
}
  </script>
</body>
</html>

Produces:

Request received:

--------------
{{"a":"b"}=[Ljava.lang.String;@7a2897ac}
============== 

So if I use $post with a stringified json string and a callback I get everything stuffed in a single parameter key. If this is normal, I would like to know why, and how I’m supposed to unravel this cleanly on the server. If it is not normal, I’d like to know what I should do to to get it in the response body using $post.

UPDATE: There is now a feature request for jquery to support contentType on $.post

  • 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-28T00:13:29+00:00Added an answer on May 28, 2026 at 12:13 am

    I think you can do this if you drop down to $.ajax

    $.ajax(
      {
         url: "http://localhost:8080/x",
         data: JSON.stringify({a: 'b'}),
         processData: false,
         type: 'POST',
         contentType: 'application/json'
      }
    );
    

    processData tells jquery not to mess around with your data and setting contentType should ensure that your backend doesn’t try and parse the json as it were a regular url encoded form.

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

Sidebar

Related Questions

Previously i have used restful wcf webservices to get the data from server.But now
multiple webapp running on same tomcat using same jvm. sometime, one webapp that have
I am writing a webapp using CodeIgniter that requires authentication. I created a model
I have a webapp that I am in the middle of doing some load/performance
I've been asked to create a stand-alone webapp using straight HTML and Javascript that
I'm currently using jquery ajax to call a pagemethod (which works great); $.ajax({ type:
I have a webapp which is built using spring 3 and tiles 2 (not
I have some backend functionality which need to be written in C# (for political,
We have a popular web-app developed using CodeIgniter. Now we want to expose our
I am developing a webapp using Spring MVC 3 and have the DispatcherServlet catching

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.