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

Guide on how to capture tweets from particular Twitter profiles

I'm currently experimenting with the twitter npm package to stream tweets from specific accounts, but I'm facing some challenges. After reviewing the Twitter API documentation, I must admit that I am a bit perplexed. To fetch details about a pa ...

Encountering a 500 error while attempting to make two separate AJAX requests in Codeigniter

Currently working on a web application using Codeigniter, I am facing an issue with three dependent <select> inputs. The second <select> is reliant on the first, and the third is dependent on both the first and second. Using jQuery and AJAX to ...

Require assistance in getting a slider operational

Hello there! I could really use your assistance with this code. I have been trying to make it work using JavaScript, but I'm determined not to incorporate any external JS files. Here is the snippet of JavaScript code I am working with: "use strict"; ...

Having trouble locating the function in one of the included JavaScript files when receiving an Ajax response?

I have implemented jquery tabs that initiate an ajax call when a tab is clicked. When the tab is clicked, it triggers the ajax call to fetch the HTML response and then appends it to the current page. However, I am encountering an issue; Within the ajax re ...

Asynchronous jQuery AJAX calls are now obsolete and deprecated

Currently, I am utilizing jquery version 1.11.2 and attempting to perform an asynchronous ajax call for form validation purposes. Below is the code snippet: <form name="form1" id="form1" method="post" action="/payment/payment.php" onsubmit="retur ...

What steps should I take to incorporate Google sign-in on my website and gather user information efficiently?

I am looking to add the Google sign-in button to my website. While I am knowledgeable in HTML, PHP and JavaScript are not my strong suits. My goal is to allow users to sign in with their Google account and securely store their information on my database th ...

Modifying the image height in a column using Bootstrap and JSON data

My webpage is dynamically generating images from a JSON file through a JavaScript file. However, the images are displaying at different heights, and I want each column to adjust to the height of the image to eliminate any gaps. Particularly, data with the ...

Using html data attributes to encode JSON data with strings

Looking for a way to pass data to JavaScript, I decided to create a template tag as shown below: from django.utils.safestring import mark_safe from django import template import json register = template.Library() @register.simple_tag def mydata(): r ...

Is there a way to determine the model name programmatically within a Sails.js lifecycle callback?

Two models are present, with one model extending from the other. For all sub-models to inherit a lifecycle callback defined in BaseObject, I need a way to retrieve the name of the model being acted upon within the callback. This information is crucial for ...

Upon registration, the user's information is successfully stored in the mongoDB database, even if the selected "username" is already in

I am currently working on a web application using the MERN stack. When registering a user with an existing email either through Postman or the front-end form, the user is not added to the database. The same logic is applied to check if the chosen username ...

Using the Ternary Operator in JavaScript to Dynamically Update HTML Elements with Angular

Is there a way to convert the code below into a ternary operator so that it can be used in an .HTML file? statusChange && statusChange === 'Employed' ? true : employmentStatus === 'Employed'; To clarify, I want to assign the re ...

Managing the onChange event for a MaterialUI dropdown component

I'm encountering an issue with validating the MaterialUI TextField component (Country list) wrapped with Autocomplete. I am trying to use the onChange event to enable the Submit button when the country field is filled in. However, the problem arises w ...

Encountering a 404 error when attempting to make an Axios post request

Utilizing Axios for fetching data from my backend endpoint has been resulting in a 404 error. Oddly enough, when I manually enter the URI provided in the error message into the browser, it connects successfully and returns an empty object as expected. Her ...

The variable declared in the useState hook is not being properly updated within the callback function

const ModifiedTweet = ({ tweet, checkedList, setCheckedList }) => { const [isChecked, setChecked] = useState(false); useEffect(() => { if (checkedList.length === 0) { setChecked(false); } }, [checkedList, isChecked]); return ( ...

How can the input validation be displayed in Ajax when the user interacts with it?

When utilizing Ajax, I only want to display validation for the input field that the user is interacting with, not all validations at once. Currently, my script shows all validations simultaneously when any input is filled out. How can I modify my code so t ...

What is the best way to choose all elements that fall between two specific elements?

Looking to grab content situated between two specific elements within an HTML structure. The HTML snippet in question is as follows... <h2>This is firsty</h2> <p>Some para</p> <ul> <li>list items</li> <li&g ...

Update the position of the dragged object following the completion of an ajax request

I am currently using jQueryUI drag and drop feature to create a captcha plugin where users drag images into a container, followed by making an AJAX call. I would like to know if it is possible for the positions of the dragged images to be reset once the AJ ...

Error: The constructor for JsSHA is not valid for the TOTP generator

Attempting to create a TOTP generator similar to Google's timed-based authenticator using the React framework. I am utilizing the bellstrand module for TOTP generation, but I am encountering issues when trying to import it into my React code. Here is ...

JavaScript is claiming that my class method is invalid, despite the fact that it is obviously a valid function

Implementing a genetic algorithm using node has been my latest challenge. After browsing through the existing questions on this topic, I couldn't find anything relevant to my issue. The problem arises when I attempt to call the determine_fitness metho ...

Designing a dynamic carousel with AngularJS

Currently facing an issue with handling JSON data in AngularJS. When I select the 'img' object, it logs to the console but doesn't get applied to the scope. Can anyone provide some guidance on this? 'use strict'; angular.module(& ...