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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:42:42+00:00 2026-05-26T03:42:42+00:00

I want to sent a JSON data to my controller’s POST handler. I do

  • 0

I want to sent a JSON data to my controller’s POST handler. I do that at my client side:

var userName = $('#userName').val();
var password = $('#password').val();
var mail = $('#mail').val();
var admin =$("#admin").is(':checked');
var user = {userName: userName, password: password, mail: mail, admin:admin};

$.ajax({
   async : false,
   type:'POST',
   url: '/uxiy/webapp/uxmer',
   data: user,
   dataType: 'json',
   success: function(data) {
       ...
   },
   error: function(data) {
       ...
   }
});

My Spring controller as follows:

@RequestMapping(method = RequestMethod.POST)
public void createUser(HttpServletResponse response, @RequestBody User user) {
    user.setName("POST worked");
    //todo If error occurs response.sendError(HttpServletResponse.SC_NOT_FOUND);
    response.setStatus(HttpServletResponse.SC_OK);
}

However when I send my data I get that error at Firebug:

“NetworkError: 415 Unsupported Media Type”

What is wrong?

PS:
An example of Firebug POST details:

Parameters  application/x-www-form-urlencoded
admin   true
mail    user@user.com
password    r
userName    userx
Source
userName=userx&password=r&mail=user%40user.com&admin=true

PS2:
After I added

contentType: 'application/json',

it started to give

"NetworkError: 400 Bad Request" 

What can be the problem, making serialization, etc?

PS3:
Here: http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/ it says:

If there are validation errors, a HTTP 400 is returned with the
error messages, otherwise a HTTP 200 is returned.

I have 400 Bad Request Error. Maybe the problem is related to that?

  • 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-26T03:42:43+00:00Added an answer on May 26, 2026 at 3:42 am

    Problem was about the JSON array. It was not a valid JSON string that was sent from client to server.


    Edit

    To clarify this, I stumbled upon this post. It is required to do a proper JSON.stringify(data) in the Ajax request. It’s strange but it’s not done by the .ajax function when setting the corresponding dataType.

    $.ajax({
        async : false,
        type:'POST',
        url: '/uxiy/webapp/uxmer',
        data: JSON.stringify(user),
        dataType: 'json',
        success: function(data) {
            ...
        },
        error: function(data) {
            ...
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to shrink the data that is sent back and forth via AJAX,
I want to configure SMTP on my web server, so that any email sent
i have been sent a directory tree of source code that i want to
I am using $.ajax function to send json data to serverside function. var jsonObjects
I'm trying to learn how to use CURL and Json to access data sent
i am getting json data from this link now i want data from html_instructions:
I'm just starting out with jQuery. I want to send JSON data to a
I want to sent the data from an Android device to PHP. I have
Good morning folks, I'm just that beginner in json, I have a formated data
I'm having a strange problem with my WCF service that returns data in JSON

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.