Sending numerous arguments via HTTP DELETE request

In my code, I am trying to send the id and dept fields in a DELETE HTTP request and then retrieve them inside the deleteData() function. However, I am encountering an issue where the values for id and dept are coming up as null within the deleteData() function.

$http['delete']('webapi/Data/delete?' + cdata.id + "&&" + cdata.lineUp)

@DELETE()
@Path("/delete")
public String deleteData(@QueryParam("id") String id, @QueryParam("dept") String dept){

Answer №1

When using the HTTP Delete method, you cannot pass data as an argument. </p>

<p><strong>This Approach Will Not Work</strong> </p>

<p>In this scenario, passing an object would look like this:</p>

<pre><code>var cdata = {
   id: 2,
   lineUp: [...]
};

// This won't work
$http.delete('webapi/Data/delete, cdata)
  .then(function(response) {
     console.log(response);
  })
  .then(function(error) {
     console.log(error);
  });

For a truly RESTful approach, you should only need to provide the id to the HTTP Delete method.

Embrace RESTFul Design

var cdata = {
   id: 2,
   lineUp: [...]
};

// Using RESTful design
$http.delete('webapi/Data/delete/' + cdata.id)
  .then(function(response) {
     console.log(response);
  })
  .then(function(error) {
     console.log(error);
  });

If necessary, you can utilize the HTTP Post method as a workaround.

Here's a Workaround

var cdata = {
   id: 2,
   lineUp: [...]
};

// This is a workaround
$http.post('webapi/Data/delete, cdata)
  .then(function(response) {
     console.log(response);
  })
  .then(function(error) {
     console.log(error);
  });

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

Retrieve data via AJAX using a combination of JavaScript and ASP

Can someone help me figure out how to retrieve the value of value1 on my server-side ASP using Javascript? I am using this Ajax code but unsure of how to do it. In my serverside code, I would like to have something like <% var newdata = value1 (which ...

In search of a JavaScript library that offers a navigation menu similar to the one on FogBugz's homepage

Does anyone know of a JavaScript library that can create a navigation menu similar to the one found on ? I am looking for recommendations. Thanks! ...

Error 404: Page not found. Sorry, we couldn't locate the Node JS and Express resource

I have been trying to access the routes /api and /api/superheroes, but I keep encountering an error message whenever I try. Not Found 404 NotFoundError: Not Found at C:\Users\mikae\Desktop\Project\node-express-swig-mongo\a ...

the sequence in which a node executes a javascript function

Trying to update req.session.cart with new values for prod.quantity and prod.qtyCount in the shoppingCart field of order.save(). The issue is that orders are being saved with default quantity and qtyCount values, even though I'm setting cartProducts[ ...

Enhancing Nativescript elements with pseudo selectors

Is there a way to apply the button:hover effect in Nativescript Buttons? I attempted the following code: Button:highlighted{ background-color: red; } Button:hover{ background-color: red; } Button:touch{ background-color: red; } ...

Grunt Alert: Unable to locate "concat" task

I'm having some trouble starting with a basic Grunt example, specifically encountering an issue with grunt-contrib-concat. This is my setup in Gruntfile.js: $ cat Gruntfile.js module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.f ...

Route users away from login view when they are already logged in using Angular UI-Router

Currently, I am tackling a project that involves Angular and Meteor while utilizing the ui-router. One issue that has arisen is that when users are logged in and manually visit the /login route, my goal is to automatically redirect them to the home page. ...

I am looking to utilize React and Next.js to map my array from an object. The component is a function employing hooks

I am attempting to map an array within an object and encountering some challenges. The structure of the object is as follows: const data = {data: (6) [{…}, {…}, {…}, {…}, {…}, {…}], page: 2, per_page: 6, total: 12, total_pages: 2} I have been ...

Utilizing JavaScript to retrieve data using AJAX

Having trouble sending emails through ajax on my website. The form is in a modal (using custombox), but all values being sent are null. How can I utilize getElementById in modal content? Link to custombox git's hub: https://github.com/dixso/custombox ...

Troubleshooting issue with Ajax.Actionlink not canceling request using jQuery's onBegin

In the "onBegin" ajax option of an ajax.actionlink, I have a function that is called. function cancelAction() { $.ajax({ data: { p: "test", z: "value" }, url: '@Url.Action("DoSomething", "TestCtlr")', type: "GET", ...

Guide to wrapping column headers in ag-Grid with Angular

I am facing an issue with wrapping column headers in my HTML table. Some columns have four words like Pre Trading Follow Up and Post Trading Follow Up, while others have three words. I attempted to use the following CSS to wrap the text to multiple lines: ...

Vue-bootstrap spinbutton form with customizable parameters

I am in need of a custom formatter function for the b-form-spinbutton component that depends on my data. I want to pass an extra argument to the :formatter-fn property in the code snippet below, but it is not working as expected. <b-form-spinbutton :for ...

Implement a variety of HTTP response codes for a REST endpoint

I'm currently utilizing express to serve the REST API endpoints for a simulated backend. One of the endpoints requires the ability to return different HTTP response codes, while maintaining a 200 status for the other endpoints. Here is a snippet of my ...

Encountering Routing Issues in Express.js Following Passport.js Authentication

My authentication setup with Passport.js is pretty straightforward. After the user successfully authenticates, I redirect them to /work like this. app.post('/login', passport.authenticate('local', { successRedirect: '/ ...

Issue with setting Y Axis intervals using ticks in d3 library

I am trying to set the Y Axis from 0 to 100 percent with intervals of 0-25-50-75-100. Despite setting ticks to 4, I am seeing Y axis intervals of 0-20-40-60-80-100 How can I adjust the Y axis to display intervals of 0-25-50-75-100? Here is the code I am ...

Dealing with errors when loading templates in angular-ui-router

When using angular-ui-router, my configuration looks something like this: .state('page', { url: '/page', templateUrl: '/page.html' }) If the template URL returns a "401 Unauthorized" error, I would like to know if it ...

If all input values within every li element are equal to zero in jQuery

Currently, I am facing an issue that I need to solve. I have multiple inputs and my goal is to check if each input has a value of 0 and is also checked. After spending an entire day searching for a solution, I am still clueless about how to proceed. I att ...

Ways to handle errors when using navigator.clipboard.writeText

document.queryCommandSupported('copy') may not be available on all browsers. I experimented with the code below, which successfully copies the link on Firefox but fails on Opera. It displays an alert indicating that the code has been copied, yet ...

What is causing the error to appear in the Android web-view when using vue.js?

During the development of my web app using Vue.js, I encountered a strange issue where everything was functioning correctly in desktop browsers but not on mobile devices. To troubleshoot this problem, I decided to install an Android emulator and use remote ...

Assembling back-end interfaces

While working with AngularJS's $http service, I've faced challenges in organizing all the backend URLs throughout my controller code. Sometimes they end up being duplicated and scattered around which can make maintenance difficult. Typically, the ...