Unusual $http Angular.js POST inquiry

Hey there, I'm facing a peculiar issue in my web development project. I have a table that acts as an input field where users can enter data and then send it back to the Spring Rest API. The data is received as a String and then parsed using the Gson library.

$http({
    method: 'POST',
    url: 'saveTableData.do',
    headers: { 'Content-Type': 'application/json;'},
    data:'tableVal'+data1
}) ;

Here is a snippet of my Spring controller:

@RequestMapping(value="/saveTableData",method=RequestMethod.POST)
public void saveTableDataToDb(@RequestBody String tableData) {

    Gson gson = new Gson();
    TableData dataFromJson = gson.fromJson(tableData, TableData.class);
}    

Although the data is being sent successfully to the backend, I am seeing the following error message in the console: Failed to load resource: the server responded with a status of 404 (Not Found)

I am wondering why this error is occurring and if it will have any impact on the project in the future.

Answer №1

I don't have much experience with Spring, but I believe the reason for the 404 error might be because your method is not returning anything.

In a simplified example, it should look something like this:

public Response saveDataToDatabase(MyObject myObject) {
    // Implement some business logic here
    Response response = new Response();
    response.setStatusCode(200); // HTTP status code for success
    return response;
}

Since you currently have a void method, my guess is that this could be causing the issue. Hope this helps!

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

How can I send a variable into the DOM using AJAX?

Apologies for posting a question earlier about creating a condition for checkbox without proper investigation. It appears that I need to pass my variables here. function setsession(sessionid, action, data) { $("#totalselection").show(); $. ...

Utilizing AngularJS to invoke a jQuery plugin

Currently, I am utilizing the fullCalendar jQuery plugin alongside AngularJS. My goal is to call the refetchResources function of the jQuery plugin from Angular. I attempted to achieve this using the following code: angular.element(document.querySelector ...

Updating a Rails form with a dynamically changing belongs_to select field

My Rails3 app has a Site model, connected to a Region model which belongs to a Country. Currently, the site form includes a select field for Region filled from the Region model. However, I want users to update this list dynamically. I attempted to create ...

How to use AJAX to dynamically populate an HTML form with data retrieved from a PHP query结果

I'm having trouble populating a form with values after running a simple search. When I execute the script, I either receive an "undefined" response or nothing at all when I try alert(data);. search.php <?php include_once 'config/config.php&a ...

The functionality of a basic each/while loop in jQuery using CoffeeScript is not producing the desired results

I've been experimenting with different methods to tackle this issue. Essentially, I need to update the content of multiple dropdowns in the same way. I wanted to use an each or a while loop to keep the code DRY, but my experience in coffeeScript is li ...

Merging angular-file-upload with multer

I am facing a challenge in integrating the angular file upload plugin with multer to create a fully Single Page Application (SPA). I am currently stuck on uploading multiple files through multer. Below is how my multer options are set up in my node route. ...

Issue: [$injector:unpr] encountered in AngularJS

I am currently working on a project involving a webApi. My goal is to display a list of students from my database. Surprisingly, everything works perfectly fine when I don't use a service (factory), but as soon as I introduce a service, things start f ...

How to accurately incorporate the "HH:MM" time format into a Date Object in JavaScript

I need to convert a specific time of the day into a Date Object. The time is in String format and is in CET (Central European Time). In CET, "16:00" translates to "15:00" in UTC during Winter time. The code snippet below achieves this conversion in node.js ...

Developing end-to-end tests utilizing the selenium-webdriver library with WebDriverJS for node.js applications

I am currently in the process of migrating tests from webdriver and Java to webdriverjs, and I have a question regarding the functionality. Can someone help me understand why this code snippet works? driver.get('http://www.google.com'); driver.f ...

Connecting a controller to a directive in AngularJS: A step-by-step guide

Imagine a scenario with the following HTML structure: <div ng-app="testApp"> <div ng-controller="controller1"> {{controller1}} </div> <div ng-controller="controller2"> {{controller2}} </div> ...

Include a requirement within an application/ld+json formatted script

I have a task to create an application using a script in the js+json format. It is crucial to include the person schema, which signals to Google and other search engines how to effectively interpret the structure of the page and its content. My current cod ...

Create a new instance of the TypeScript singleton for each unit test

I have a TypeScript singleton class structured like this: export default class MySingleton { private constructor({ prop1, prop2, ... }: MySingletonConfig) { this.prop1 = prop1 ?? 'defaultProp1'; this.prop2 = prop2; ...

What occurs when Click events are triggered on an <object> element?

I have set up a div, and inside that container, I embedded an SVG image using object (which I plan to manipulate later...). <div id="click-me"> some random Text <object data="some.svg" /> </div> Next, I added event listeners for t ...

JSON data is returned as Object Object

Trying to work with a JSON object and need to stringify it for localStorage: $http.post('http://localhost:8000/refresh', { name: $scope.name, email: $scope.email, token: $rootScope.devToken, platform: ionic.Platform.platform() }).then( ...

Leverage AJAX data to dynamically generate an input field within a Laravel application

. Hey everyone, I'm currently working on implementing ajax for a search functionality. The goal is to display links to the search results' pages along with checkboxes next to each result, allowing users to select orders for printing. Although I ...

Tips for removing < and > symbols from the XML response on the client side

I have received a response from the server in XML format, containing partial information as shown below: <list> <Response> <cfgId>903</cfgId> <recommendations> &lt;Rule&gt; ...

Having trouble converting the file to binary format in order to send it to the wit.ai api through node.js

I am having trouble converting an Audio file to Binary format for sending it to the Wit.AI API. The node.js platform is being used for this purpose. On the front-end, user voice is recorded using the Mic-recorder Module. Any guidance or suggestions would b ...

It is impossible for Javascript to access an input element within a gridview

I have developed an asp.net page that allows a site administrator to select a user as the 'systems chair'. The page displays users in a gridview and includes a column of radio buttons to indicate who the current chair is or to change the assigned ...

Retrieving the class name using jQuery

In my HTML code, there is a div with three classes defined as: <div class = "a b c"> .. </div> My goal is to access only the class b using the .attr() method. Is this achievable? ...

leveraging jQuery mobile for asynchronous requests

I've been attempting to print a jQuery mobile element using ajax, but I'm running into an issue where the result isn't being encoded as jQuery mobile is intended to do. Below is a simplified excerpt of the JavaScript code responsible for t ...