Error 405: Javascript page redirection leads to Method Not Allowed issue

After receiving the result from the ajax success method, I am facing an issue where the redirection to another page is being blocked and displaying the following error:

Page 405 Method Not Allowed

I am seeking suggestions on how to fix this as I need to successfully redirect to the desired page.

This is what I have attempted so far:

function callinsert(db, tbl, pk, jobj) {
    $.ajax({
        beforeSend: function(xhr) {
            xhr.setRequestHeader("Authorization", "Bearer " + at);
        },
        url: "MYURL/Insert?database=" + db + "&tablename=" + tbl + "&pk=" + pk,
        contentType: 'application/json',
        data: jobj,
        dataType: "json",
        async: false,
        type: "POST",
        success: OnSuccessInsertEmployee,
        /*Create a Function to run the Success Action */
        error: errorAction
    });

}



  function OnSuccessInsertEmployee(data) {
//In this part of the code, I want to redirect to another page
        location.href = "xxxx.html";
    }

Answer №1

It appears that there are two distinct ID names being utilized for the forms, which may be causing issues with redirection upon submission.

To resolve this issue, consider implementing the event.preventDefault() jQuery function within your script to prevent default form submission behavior.

Answer №2

Encountering the HTTP 405 method not allowed error typically indicates that the method being used is available on the server but not permitted for the type of request being made.

To address this issue, ensure that the page is accessible and that either HTTPGet or GET methods are allowed for the requested resource or file. Verify that xxxx.html or any redirected links are also accessible.

If you are using a POST method, confirm that it is returning data successfully. This problem often arises when a POST request is made but the WebAPI is missing the necessary [HttpPost()] attribute on the called Web method.

UPDATE


Check if your IIS / Server allows HTML files to be served. While it is typically allowed by default, some individuals may have removed default handlers for security or performance purposes.

Inspect the Handler Mappings:

https://i.sstatic.net/mHMvH.jpg

Ensure that the StaticFile entry for * exists, is enabled, and is permitted for both GET requests and reading access.

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

Customize Django to assign a value for ajax requests across all template files

My website utilizes ajax content loading for page contents. In every page, I have a check to see if the request is ajax or not: if request.is_ajax(): return render(request, 'home.html', {'posts': posts, ...

Is it necessary to use Hapi.js on the client side in order to establish a websocket connection using the Hapi.js protocol?

Currently, I am in the process of developing an API using Hapi and requiring WebSocket functionality. After some research, it appears that Nes is the preferred choice to integrate with Hapi for this purpose. Fortunately, Nes simplifies the process signific ...

Is there a way to identify the source of a div's scrolling behavior?

While working on a complex web page that involves multiple JQuery Dialogs and other widgets, I encountered a frustrating issue. Some of the dialogs contain divs with scrolling abilities (using overflow-y with a fixed height). Whenever I click on one dialog ...

JavaScript switch statement and case expression

Struggling to use boolean expressions within a switch statement to search for undefined values and manually change them. When using an if statement, the process is easier. For example: if statement if(Item1 == undefined) { item1 = "No"; } else if (Item ...

How can I customize button colors in react-bootstrap components?

Changing colors in react-bootstrap may be a challenge, but I'm looking to customize the color of my button beyond the primary options. Any suggestions on how I can achieve this using JS and SCSS? ...

When attempting to send emails, SendGrid encounters an error and fails to provide an error code

Earlier today, I successfully sent out a series of emails using SendGrid. It was quite a large number of emails, as I needed to create multiple user accounts with attached email addresses. Thankfully, everything went smoothly and all the emails were delive ...

What is the process for defining custom properties for RequestHandler in Express.js middleware functions?

In my express application, I have implemented an error handling middleware that handles errors as follows: export const errorMiddleware = (app: Application): void => { // If the route is not correct app.use(((req, res, next): void => { const ...

How does ReactJS determine the appropriate port to use for making requests?

I am using ASP.NET Web API for the server side and ReactJS for the client side. I have a question regarding how to dynamically assign the port number for the client to make requests to the server. Currently, my server is running on port 7082 and the connec ...

What is the best way to retrieve a list of customers within a specified date range?

How can I retrieve a list of customers within a specified date range? My frontend react app includes starting and ending date pickers, but I'm unsure how to query the data using mongoose in my express app. Below you'll find my mongoose model and ...

I seem to be having trouble with my JavaScript code when attempting to search for items within

I want to implement an onkeyup function for a text input that searches for patient names from column 2 in my table. However, it seems to be not working properly as I don't get any results in return. Below are the snippets of what I have done so far. ...

Update with the string before it in a JSON list

Within a JSON file, I came across an array that requires the 'TODO' placeholder to be replaced with the entry above it. To elaborate, the initial "TODO" should be substituted with "Previous question" and the subsequent one with "Next question". ...

React component will automatically rerender if the cache is disabled in the Chrome browser

In my React application, I am utilizing 'react-image-pan-zoom-rotate' to display images. Visit the GitHub repository here The image I am displaying is sourced from an external service and passed to both libraries for rendering. Lately, I have ...

Is there a way to accurately retrieve the width of an element within setInterval without any delay?

I'm currently experimenting with increasing a progress bar using the setInterval function. So far, it seems to be functioning properly. var progressBar = $('.progress-bar'); var count = 0; var interval = setInterval(function () { va ...

Troubleshooting issue: Asynchronous functionality not working with Ajax.BeginForm

Struggling to grasp ASP.Net MVC and facing challenges with using Ajax.BeginForm to update a partial view asynchronously. Here's the code snippet in the view for the action: @using (Ajax.BeginForm( new AjaxOptions { ...

Displaying Images on top of Images with React/Javascript/NextJS

I have two images. Let's say image 1 is a thumbnail for news content. I would like to overlay a promotional PNG banner on top of this image and create a new output image. This output image will be used as the OG (Open Graph) image. How can I achieve t ...

What is the standard root directory in the "require" function's context?

After spending hours struggling to set up a simple "require" command, I've come to the conclusion that var example = require("example") only works if there's an example.js file in the node_modules directory of the project. I'm encountering ...

View is unable to trigger the success attribute

Currently, I am delving deep into Backbone JS and facing an issue where the 'success' function in 'EditUser' is not being triggered. I would greatly appreciate it if someone could guide me on what changes I need to make in the code? B ...

Controller receiving empty object array from FormData

I am encountering an issue with my ajax call to the controller, where I am passing FormData() containing an array of objects and other properties. The list array that I pass seems to have 0 elements in the controller. Can anyone assist me with this problem ...

Unique alphanumeric code following the inclusion of a JavaScript file

I'm encountering an issue with a webpage that incorporates two JavaScript files. When inspecting it using firebug, I noticed that every time the page loads, these two files are included with the prefix ?_=someRandomNumber I'm unsure about the or ...

Flipping numbers in Arabic font using PDF kit

Currently, I am utilizing the pdfkit library in my Node.js application for PDF generation. However, I encountered an issue while attempting to incorporate Arabic text. The problem lies in the fact that it consistently rearranges the numbers within Arabic t ...