Encountering a HttpMediaTypeNotAcceptableException while making a jQuery ajax request after upgrading to Spring 3.2.4版本

Whenever I attempt to execute a jQuery ajax call, I am facing the

HttpMediaTypeNotAcceptableException
.

The current configuration that I have includes:

Within the context (which is in the classpath), I have the following:

<context:component-scan base-package=" group package" />
<mvc:annotation-driven />

Additionally, in the servlet-config file, I have the following setup:

<context:component-scan base-package="controller packages alone" />
<mvc:annotation-driven />

I have also included jackson-mapper-asl 1.9.13 in the pom.xml file and utilize spring core 3.2.4 along with security 3.1.4.

My jQuery ajax call looks like this:

$.ajax({
    url : "checkUser.html",
    cache : false,
    type : "post",
    data : "email=" + $('#email').val(),
    success : function(response) {
        successful callback;
    }
});

Despite these configurations, I continue to receive the following exception message:

org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation

Answer №1

For a more detailed explanation, check out this link:

To customize acceptable media types, you can do the following:

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
  <property name="mediaTypes">
  <map>
    <entry key="html" value="text/html"/>
    <entry key="json" value="application/json"/>
  </map>
 </property>

You can also send parameters simply like this:

var url = "/checkUser/" + $('#email').val() + ".htm";
    $.ajax({
        type: "POST",
        url: url,
        success: function(msg){

In the Controller, you would use:

    @RequestMapping(value = "/checkUser/{email}",method = RequestMethod.POST)

Answer №2

Unfortunately, I encountered an issue after upgrading to the Spring 3.2 version where my pages stopped working. The problem was caused by a change in Configuring Content Negotiation - now content negotiation is done through file extensions by default.

To address this issue, I had to disable the file media type extension. For more information on how to do this, you can visit this link.

<bean id="contentNegotiationManager"
    class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
    <property name="favorPathExtension" value="false" />
    <property name="favorParameter" value="true" />
    <property name="mediaTypes">
        <value>
            json=application/json
            xml=application/xml
        </value>
    </property>
</bean>

If you're facing a similar issue, you can refer to this post for more info: HttpMediaTypeNotAcceptableException after upgrading to Spring 3.2

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting Issue with Internet Explorer failing to update Asp.Net MVC3 Partial View

I am experiencing an issue with a page that includes a div for a partial view loaded via an ajax request. $.ajax({ url: 'CompleteSessions', success: function (data) { var selector = $('#complete-session-sect ...

Selecting elements in VueJS and jQuery using query selectors

I'm currently facing an issue with accessing a DOM element inside a .vue component. It seems like the element hasn't rendered yet. One workaround that I found is using a setTimeout function: setTimeout(() => { $('.element').do_ ...

Manipulating variables in Jquery is not possible during an ajax success event

I implemented a code feature that uses ajax to load content when a user scrolls to a specific part of the page. To prevent the content from being loaded multiple times, I introduced a boolean variable that should toggle after each ajax call, preventing the ...

Transforming with Babel to create pure vanilla JavaScript

Our current development process involves working with a custom PHP MVC Framework that combines HTML (Views), PHP files, and included JS with script tags (including JQuery, Bootstrap, and some old-fashioned JS libs). During the development stages, we want ...

What should I designate as the selector when customizing dialog boxes?

I am attempting to change the title bar color of a dialog box in CSS, but I am running into issues. Below is the HTML code for the dialog box and the corresponding CSS. <div id="picture1Dialog" title = "Title"> <p id="picture1Text"> ...

When an element is appended, its image height may sometimes be mistakenly reported as

I am dynamically adding divs and I need to retrieve the height and width of an image. Based on this information, I have to apply CSS to the MB-Container class. For example: if the image is portrait orientation, set container width to 100%. If it's ...

How can you retrieve newly added DOM elements from a PartialView using Ajax.BeginForm?

Below is a snippet of code that loads a Partial View within a div element: <div id="_customerForm"> @Html.Partial("~/Views/Customer/_customerForm.cshtml", Model.customerForm) </div> The Partial View contains an Ajax Form as shown ...

Retrieve the identification number from the code snippet containing the "append(<tr><td="ID">..." template

I have a table that I'm populating with data from a firebase database using the append() function. $("#table_body").append("<tr><td>" + name + "</td>" + "<td>" + brand + "</td>" + ...

Could someone provide an explanation for this Jquery?

$(document).ready(function () { if ((screen.width >= 1024) && (screen.height >= 768)) { alert('Screen size: 1024x768 or larger'); $("link[rel=stylesheet]:not(:first)").attr({ href: "style2.css" ...

Encountering an issue when trying to upload a file: Spring 4 and Angular JS throwing error stating that the current request is not a

Currently, I am utilizing Spring 4 along with AngularJS. To handle multipart requests, I have included commons-fileupload-1.3.2.jar and commons-io-2.4.jar in my project. However, I encountered an error stating "org.springframework.web.multipart.MultipartEx ...

Issue with HighCharts: Bar columns not extending to the x-Axis when drilling up

I am encountering an issue with HighChart/HighStock that I need help with. To illustrate my problem, I have set up a JSFiddle. The problem arises when a user drills down on a bar column, causing the y-axis to shrink and consequently making the x-axis appea ...

Ajax issue: unable to retrieve $_SESSION data. Works on local environment but not on web server

I've been working on a website project that involves using jQuery to interact with a database. I store the user ID in a session for updating and deleting purposes. Everything seems to be running smoothly on my localhost (Wamp server), but when I uplo ...

Version 3.1 or higher of Django is required along with the use of the `is_ajax

HttpRequest.is_ajax() has been deprecated since the release of version 3.1. I am looking to serve HTML content when the page is accessed from a browser, and return JsonResponse when called from JavaScript or programmatically. I need advice on how to achi ...

What is the best way to retrieve data from Firebase and then navigate to a different page?

I am facing an issue with my app where I have a function that retrieves data from Firebase. However, after the completion of this Firebase function, I need to redirect it to another page. The problem is that when I press the button, the redirection happe ...

Uploading files seamlessly without the need for refreshing the page

On my HTML page, I have a form input that allows users to upload a file. Here is the code snippet: <form action = "UploadFile.jsp" method = "post" target="my-iframe" enctype = "multipart/form-data"> <input type = "file" name = "file" ...

Guide on how to generate a JSON array structure for a collection of Plain Old Java Objects (POJOs) utilizing the code

I've been searching for a solution to convert a list of POJOs to JSON. We've previously used Codehaus Jackson with Spring MVC. What I'm trying to achieve is not an AJAX call with the @ResponseBody action, but rather a utility method to conve ...

Inquiring about the rationale behind using `jquery.ui.all.css` specifically

I'm curious about the impact of jquery.ui.all.css on Tabs As soon as I remove it, <link rel="stylesheet" href="jquery/dev/themes/base/jquery.ui.all.css"> My tabs stop functioning. Here's my query: What exactly does the jquery.ui.all.cs ...

The parameters of a submitted form in JQuery are constantly changing

I attempted to pass a value to another page through the URL. I cannot hardcode it directly in the HTML because I need to gather information from multiple steps first. Therefore, I must modify the form action before it is submitted. Below is the form struc ...

Tips for exchanging JSON data between HTML and PHP using jQuery Ajax?

Hello there! I am just starting to learn PHP and jQuery, and I have been experimenting with some code to understand how things work. However, I seem to be having issues with sending data back and forth between my webpage and the PHP file on the server. Her ...

Is it possible to set the input form to be read-only?

I need to create a "read-only" version of all my forms which contain multiple <input type="text"> fields. Instead of recoding each field individually, I'm looking for a more efficient solution. A suggestion was made to use the following: <xs ...