Sorry, the requested page is unavailable because the request method 'POST' is not supported

I am trying to use AJAX to send form data to my controller. Here is what I have attempted so far..

My JavaScript function

<script>
      function sendDataToController(){


          $.ajax({
            type: "POST",
            url: "./sendData",

            success: function(data){
                console.log("SUCCESS ", data);
            },
            error: function(e){
                console.log("ERROR ", e);
            }

        });
      }
</script>

My Controller

@RequestMapping(value = "/sendData", method = RequestMethod.POST )
   public String processFormData(HttpServletRequest request) throws ParseException {

}

I'm not sure where I'm going wrong as I am encountering the following error in the controller:

org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported WARNING: Request method 'POST' not supported

Any help to resolve this would be greatly appreciated.

Answer №1

Experiment with this code snippet and use the browser developer tool to examine the network tab for the generated URL during an AJAX call.

<script>
  function initiateRegistration(){
      var context = "${pageContext.request.contextPath}";

      $.ajax({
        type: "POST",
        url: context +"/initiateRegistrationProcess",

        success: function(response){
            console.log("SUCCESS ", response);
        },
        error: function(error){
            console.log("ERROR ", error);
        }

    });
  }
</script>

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

Activate the Giphy search feature in the Slack Nestor bot's response

How can the nestor bot be configured to use a giphy search when replying in a Slack channel where the giphy plugin is active? Can something like msg.reply('/giphy ' + text, done); be used for this purpose? ...

Tips on incorporating the vue package

I recently started using Vue and decided to incorporate a plugin called vue-toastr. I'm attempting to integrate it with Laravel, which already has Vue set up with the plugin. Unfortunately, I keep encountering an error that says "TypeError: Cannot rea ...

Enabling and disabling HTML image input based on checkbox selection

I have utilized the code below to toggle the status of the image button between enabled and disabled modes using JQuery. Here is the code for a checkbox in Yii format: <?php echo CHtml::CheckBox('TermsAgreement','', array ('ch ...

I'm having trouble understanding the distinction between this.query and this.query.find(). Can you explain the difference to me?

Currently, I am working on a MERN tutorial where I am developing a full E-commerce application. This is the class that handles querying and various other tasks. constructor(query, querystr) { this.query = query; this.querystr = querystr; con ...

Tips for creating Angular unit tests that involve setting @Input values and mocking them

As a beginner in Angular, I am currently diving into writing test cases. How can I approach writing unit tests for the following code snippet in Angular/TypeScript? @Input() set myOutputData(res: any) { this.apiError = ''; if (!re ...

Is a streamlined jQuery version of the Slider control designed specifically for mobile devices on the horizon?

Currently, I am developing a mobile web app and would like to incorporate the JQuery Slider control. http://docs.jquery.com/UI/Slider However, in order to do so, it seems that the entire JQuery core (29kb compressed & gzipped) is needed. My question ...

What is the method to access a variable within an attribute that is not prefixed with ng-*?

For my project, I am utilizing a datePicker called in conjunction with AngularJS. Here is an example of how I incorporate it: <div class='col-md-2'> <div class="form-group"> <label>End date</label> <div clas ...

The code functions properly on React Webpack when running on localhost, however, it fails to work once deployed to AWS Amplify

As I work on my React.js app, I encountered an issue with hosting pdf files on Amplify. While everything runs smoothly on localhost/3000, allowing me to access and view the pdf files as desired either in a new tab or embedded with html, the same cannot be ...

Implementing a powerful multi-role authorization system in React

I am currently developing an application with multiple user roles (admin, user, manager). I am trying to restrict access to the admin route from both managers and general users, and also render the UI based on the user's role. I have attempted this bu ...

Determine who the creator of the clicked div is

I'm sorry if my explanation is a bit difficult to comprehend. Here is the code snippet in question: names.push(newName); var strName = newName; var newName = document.createElement('p') newName.setAttribute('id', newName); documen ...

Modifying the outline color of SVG icons against various backgrounds

Is there a way to change the color of my SVG icon based on its background? I have this star icon with the following code: <svg width="33" height="33" viewBox="0 0 33 33" fill="none" xmlns="http://www.w3.org/2 ...

Alter the color scheme using jQuery

Exploring the world of websites, I've come across many with a unique color switch feature. Users have the ability to choose a color, and the entire page transforms to match their selection. Check out these links for some examples... http://csmthe ...

I am attempting to retrieve the information entered into the textbox, search for it within my database, and display the results beneath the textbox for reference

<!----- fetchCedulaData.php This script retrieves data from the database and performs a search to return results ---------------------------- - --> <?php require("connection.php"); $cedula=$_REQUEST["cedula"]; //$cedula="0922615646"; echo $cedu ...

Generate a variety of files using GraphicsMagick

I'm trying to enhance my function that deals with uploaded images. Currently, it captures the image, converts it, and saves only one version of it on the server. However, I would like to modify it to achieve the following goals: Goals: Save multipl ...

Steps for resetting the counter to 0 following an Ajax Refresh or Submission to the database

I have been working on a code that successfully sends multiple data to a MySQL Database using JQuery Ajax. Everything works smoothly, but I encountered an issue when trying to refresh the page with ajax and add a new record; it populates the number of time ...

Splitting a variable from the input into two parts for constructing the URL in Perl

Currently, I am extracting data from a .txt file to use for web scraping. However, the URL structure requires me to manipulate a specific variable by adding and subtracting 2 from it. For instance, if the value is 2342, I must generate 2340 and 2344 to inc ...

Mastering the Art of Live Search in Drop Down Multi Select

I need to develop a search functionality similar to the one found on . This search should allow users to select options from a dropdown menu or type their own search query, and provide live search results. I attempted to use the jQuery plugin https://www.j ...

Validating an email address without the "@" symbol or if the "@" symbol is the last character

I've been working on validating email addresses using regex, but I'm encountering an issue. The problem is that the validation fails for emails that don't contain the "@" character or have it at the end of the word. For example, if I type "a ...

I'm experiencing some compatibility issues with my script - it seems to be functioning correctly on desktops but not on mobile

Below is a script I've implemented on an html page to toggle the visibility of divs based on user interaction. <script> $(document).ready(function(){ $("#solLink").click(function(){ $(".segSlide").hide(), $(".eduSlide").hide ...

Execute supplementary build scripts during the angular build process

I've developed an Angular application that loads an iframe containing a basic html page (iframe.html) and a Vanilla JavaScript file (iframe.js). To facilitate this, I've placed these 2 files in the assets folder so that they are automatically cop ...