The path is visible, yet the ajax call does not make it through - it's simply "off course"

rake routes is used to verify the existence of a route:

    control1_route1 DELETE /control1/route1(.:format)

However, when attempting to make a "delete" request to this route:

  var url = "<%= control1_route1_url %>";
  $.ajax({url: url, type: "DELETE"}).
    done(function(data) {
      alert("ok");
    });

The request never reaches its destination and results in a 404 error. What could be causing this issue?

Additionally:

  # controller
  def route1
  end

  # routes
  delete "control1/route1" => "control1#route1"

Answer №1

There is a mistake in this code snippet:

$.ajax({url: url, type: "DELETE"})

To correct it, change type to method like this:

$.ajax({url: url, method: "DELETE"})

As stated in the jQuery AJAX documentation, you should use method to specify the HTTP method for the AJAX call.

By making this adjustment, your request should now correctly reach the designated route.

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 to troubleshoot an Ionic exception occurring during the execution of any Ionic command?

Whenever I attempt to run an ionic command, I keep encountering this error message: { Error at FatalException.Exception (C:\Users\crist\AppData\Roaming\npm\node_modules\ionic\node_modules\@ionic\cli-u ...

Adding a value to a.getAttribute in JavaScript or jQuery: A definitive guide

As a newcomer to JavaScript and jQuery, I am facing an issue with a form text field. I am attempting to append a value to it, which will then be added to Google Maps places. However, I keep getting an error message saying "a.getAttribute is not a function. ...

Navigating through props outside a class component in React

I'm struggling to grasp how I can access props that are defined outside of a React class component. In the code snippet below, all props are clearly outlined except for this.props.checkboxArray, which is currently throwing an error "cannot read prope ...

Tips for adjusting the height of MUI Date Picker to fit your preferences

<Box sx={{ m: 1 }}> <LocalizationProvider dateAdapter={AdapterDayjs}> <DatePicker label="Enter Date" slotProps={{ textField: { height: "10px" } }} ...

In the event of a 404 error, simply direct the user to the pageNotFound before ultimately guiding them back

I'm developing a website with Node JS and I want to implement a feature where if the user attempts to navigate to a non-existent page, they are redirected to a "Page Not Found" message before being automatically taken back to the home page after a few ...

Transforming PHP shortcode into JQuery functionality

My website is built on Wordpress, and I use javascript to load some of the content. Here's an example: jQuery(".portfolio-fs-slides").css({"display":"none"}).prepend('<div class="portfolio-fs-slide current-slide portfolio-ppreview"><d ...

What is the best way to distribute components between two NextJS projects?

Confused about the best way to share ReactJs components between two NextJs applications - one for e-commerce and the other for a manager portal. In the e-commerce app, there are various UI components that I want to reuse in the manager portal. Considering ...

I'm confused as to why MongoDB is flagging this as an invalid JavaScript object when attempting to run the update method

Encountering an error while attempting to update a record: (node:2018) UnhandledPromiseRejectionWarning: MongoError: document must be a valid JavaScript object Here's the code in question: global.db.collection("groups").find ...

A guide on retrieving information from a database with PHP and transferring it to Javascript

As I work on creating a website using HTML, CSS, MySQL, and JavaScript, my goal is to allow users to log in and engage in a quiz with 40 questions. Below is the JavaScript code for a countdown timer that includes the "questions" variable. After 40 seconds ...

The model I exported from Clara.io is not showing up on the Three.JS canvas, only a black square is

I recently started using Three.JS and imported an object I exported as a JSON from clara.io. Unfortunately, the object is not appearing in the canvas, instead I see a black square with the dimensions I specified in the variable (400 by 300 pixels). Below ...

Should the use of readFileSync() during the initialization of a Node.js web application be avoided?

I have a Node app that serves web pages with static HTML-snippet files included conditionally. I am considering implementing a cache map for these snippets by adding the following code to my Express's app.js file: var cache = Object.create(null); cac ...

Strategies for efficiently creating reusable HTML templates for recurring content blocks?

I am just starting out in web development and have encountered a problem with navigating through my page. The layout of the pages is the same, except for a div container. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

Retrieving information and implementing condition-based rendering using React's useEffect

I am currently developing a MERN stack application that retrieves information regarding college classes and presents it in a table format. The CoursesTable.js component is structured as follows: import React, { useState, useEffect } from 'react'; ...

How to Implement Infinite Scrolling in Ionic Framework Using HTTP Requests

Recently, I started using the amazing ionic framework and I am new to angular. I have a web service up and running, and my app is supposed to load data. I have succeeded in retrieving data, however, the WordPress rest API sends data in the form of pages. I ...

"Learn how to update an existing table row and populate its cells with JSON data retrieved from a successful AJAX request without creating a

Currently, I am utilizing CouchCMS. The platform offers a feature known as repeatable regions which essentially generates tables to showcase recurring content. The defined repeatable region looks like this: <cms:repeatable name="item_detail" ...

Illustration of a D3 graph demo

I'm currently working on modifying a d3.js graph example originally created by Mike Bostock. My goal is to replace the d3.csv method with d3.json. I made adjustments to parts of the original code, but unfortunately, my graph has disappeared without an ...

When the form is submitted using jQuery AJAX, the page is refreshed

Having an issue with submitting a form using jQuery ajax. Whenever I submit the form, the page is reloading. I've tried using preventDefault(), but it's not solving the problem. This is the HTML code for my form: <form action="" method="post ...

Using Jquery to trigger a function with varying parameters by clicking on multiple buttons

I have a query about extracting values from input text fields in my code. Is there a solution for this issue? <?php for ($i=0;$i<3;$i++){ echo ('<input type="text" class="form-control" name="vec" id="vec'.$i.'" value=" ...

Enter a keyword in the search bar to find what you're looking

I am working on a form where users can select their occupation from a list that is stored in a separate .js file. The list includes various occupations like 'AA Patrolman' and 'Abattoir Inspector'. var occupationSelect = "<select id ...

A guide on triggering a new chart to appear beside the adjacent <div> when a bar is clicked in a highchart

I'm a beginner with Highcharts and I have a requirement for two charts (let's call them Chart A and Chart B). Creating one chart is straightforward. What I need is, upon clicking on a bar in Chart A, a new chart (Chart B) should open next to the ...