The post request was successful, but unfortunately it redirected to an error page

Encountering an unusual problem while executing a POST request. There are three different forms on the same page, all with a post method. The first form functions correctly.

However, the other two forms encounter an issue: upon clicking the save button, it redirects to an error page with the message

Cannot POST /http://localhost:4000/cards
. The URL of the page becomes
http://localhost:8080/http://localhost:4000/cards
, which combines my local server URL with the JSON server URL.

After refreshing the page, the request seems to have been successful as a new card is added.

Provided below is a simplified version of my code :

<form action="/http://localhost:4000/teamsettings" method="POST">
  <input name="title" class="input-source" v-model="teamsetting.name" type="text">
  <input name="description" class="input-source" v-model="teamsetting.description" type="text">

 <div type="submit" @click="submitTeamG(teamsetting)">Save</div>
</form>



<form action="/http://localhost:4000/cards" method="POST">
  <input v-model="title">
  <textarea class="input-resume" v-model="description"></textarea>

  <button type="submit" @click="subCard">Save</button>
</form>



<form action="/http://localhost:4000/cards" method="POST">
  <input v-model="card.title">
  <textarea class="input-resume" v-model="card.description"></textarea>

  <button type="submit" @click="modifyCard">Modify</button>
</form>

Further, here are my Axios POST requests :

methods: {
        submitTeamG(teamsetting) {
            axios.put('http://localhost:4000/teamsettings', {
                name: teamsetting.name,
                description: teamsetting.description
            })
                .then(function (response) {
                    console.log(response.data);
                })
                .catch(function (error) {
                    console.log(error);
                });
            window.location="/backoffice";
        },

        subCard() {
            axios.post('http://localhost:4000/cards', {
                title: this.title,
                description: this.description,
            })
                .then(function (response) {
                    console.log(response.data);
                })
                .catch(function (error) {
                    console.log(error);
                });
            window.location="/backoffice";
        },

        modifyCard(card) {
            axios.put('http://localhost:4000/cards', {
                title: card.title,
                description: card.description,
            })
                .then(function (response) {
                    console.log(response.data);
                })
                .catch(function (error) {
                    console.log(error);
                });
            window.location.reload();
        }
    },

Observing a 404 error in the console before being redirected to the error page, yet the new data is successfully added to the JSON file in the database. What could be causing this issue?

Appreciate your assistance and time :)

Answer №1

Instead of using window.location="/backoffice";, opt for

window.open("/backoffice","_self");

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

Grid of domes, fluid contained within fixed structures and beyond

I've been grappling with this issue for a while now, and have had to rely on jQuery workarounds. I'm curious if there is a way to achieve this using CSS or LESS (possibly with javascript mixins). The page in question consists of both fixed and f ...

Tips for simulating a dropdown selection from a remote location

I have multiple dropdown selection menus where changing the option in one menu affects the options in the next menu, and so on. I want to programmatically trigger a change (without user interaction) in the dropdown menu that will activate the JavaScript f ...

Load Vue dynamically to implement reCAPTCHA script

I am looking for a way to dynamically load a script like recaptcha specifically within the Register.Vue / login.Vue component. <script src="https://www.google.com/recaptcha/api.js?onload=vueRecaptchaApiLoaded&render=explicit" async defer> </s ...

Display a preview of a React component

Currently facing a challenge where I need to create a form for users to adjust the title, background color, button background, text color, and other settings of a component. I want to provide a live preview of the component as the user makes changes. I en ...

Is there a way to incorporate the req.setHeaders method with the res.redirect method in the same app.get function?

var express = require('express'); var app = express(); var PORT = process.env.PORT; app.get('/', function(req, res){ res.json('To search for images, enter your query parameters like this: https://api.cognitive.microsoft.com/bi ...

Spin the sphere texture in Three.js

Currently, I am working on rendering a sphere through three.js. While applying a texture to the sphere works well, I am having some difficulties rotating the texture to align it with marker positions. The issue arises when trying to place markers over Kag ...

How do you adapt nested JSON data when editing sub-columns in a Webix datatable?

Within my Webix datatable, I am utilizing multiple columns under a single column header using the colspan property. The table is populated with JSON data that has an Array structure to populate those sub-columns. I have noticed that when I make edits to a ...

The Bootstrap navigation pills do not function properly when using a forward slash in the tab link

I am currently working with Bootstrap and using nav pills. I have noticed that if I include a / sign in the link of a tab, it causes that specific tab to malfunction and triggers a JavaScript error in jQuery's own code when clicked on. How can I go ab ...

The parsing of the JSON file in Racket did not return any results

Here is the code snippet I am working with: #lang racket (require json) (define test-json (read-json (open-input-string (file->string "test.json")))) (hash-ref test-json "foo") test.json { "foo":"bar", ...

Having trouble with GLB file loading in three.js?

My GLB file is not displaying in my Three.js world. Despite following all the documentation and tutorials, the model is not showing up. The world loads perfectly and everything works fine, except for the model not appearing. I am on a journey to create a ...

Fixing the Vue.js error "uncaught exception: Object" when making a GET request

When making a GET request to a firebase database, I am encountering an issue where the data logged in the console displays as "uncaught exception: Object". . Prior to this, I successfully made a POST HTTP request without any problems. However, I have not ...

Troubleshooting Datatables and ASP.net - The mysterious HTTP Error 404.15 that leaves you lost and

When making a request with datatables, I am encountering an issue with the URL being too long. The current URL is as follows: http://localhost:12527/MyHandler.ashx?draw=1&columns%5B0%5D%5Bdata%5D=0&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bse ...

Unlocking the secrets of retrieving the URL query string in Angular2

I'm struggling to extract the URL query string returned by the security API, resulting in a URL format like this: www.mysite.com/profile#code=xxxx&id_token=xxx. My goal is to retrieve the values of code and id_token. In my ngOnInit() function, I ...

Implementing a dual-level hierarchical organization of objects in AngularJS

I am currently developing an Angular application that integrates a cell modifier within a custom cell template in Angular Bootstrap Calendar. Instead of traditional event displays within each cell, I am incorporating sets of tables used for shift sign-ups ...

What is the Best Way to Send JavaScript Variables to MYSQL Database with PHP?

I am having trouble sending my variable to a MySQL database. The database only displays the variable when using the HTML input tag. The error message I received was "Undefined index: rate & amount." Seeking assistance to resolve this issue. Thank you! ...

JavaScript integration for inviting friends on Facebook

While the title may make it seem like a duplicate, this is actually a unique question. Keep reading. I am looking to develop a JavaScript script that can automatically send friend invitations to specific users. How should I go about doing this? The idea ...

Modify the input placeholder text in Stripe's "postalCode" field to display as "ZIP/Postal" instead of the default options "ZIP" or "Postal Code" by manually making the necessary adjustments

For my nuxt.js app, I am using "@stripe/stripe-js": "^1.9.0" and need to update the placeholder text in this input field: <input class="InputElement is-empty Input Input--empty" autocomplete="postal-code" autocorrect="off" ...

Implement dynamic message based on user interaction using v-on:click in Vue

I am trying to show my IP address when a button is clicked in Vue. Check out my code below: <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3244475772001c071c0305">[email pr ...

Experiencing an issue where the canvas element fails to render on mobile Chrome browser,

I've encountered an issue with a script that draws a canvas based on the background color of an image. The image is loaded dynamically from a database using PHP. The responsive functionality works fine on mobile Safari, but not on Chrome. When the re ...

Create a separate server session specifically for handling an ajax request?

Currently, I am working with a collection of PHP server-side scripts that manage user session state by utilizing PHP sessions extensively for authenticated users. For the client side within a mobile application and using Jquery ajax, I am striving to esta ...