Server Receiving Missing Post Parameters

I've developed a straightforward $resource factory.

.factory('Order', order)

order.$inject = ['$resource', "ApiEndpoint", "UserRecord"];

function order($resource, ApiEndpoint, UserRecord) {
  return $resource(ApiEndpoint.url + 'orders.json', {}, {
    create: {method: 'POST', url: ApiEndpoint.url + 'orders.json'}
  });
}

Here's the snippet of code I'm executing.

var params = {product_id: 32342, variant_id: 536341};

Order.create(params, function( resp ) {
  console.log("success");
});

Whenever I trigger the create function, the parameters aren't being passed through. None of the parameters are getting through. What could be causing this issue and how can I resolve it?

Answer №1

Based on information from the documentation:

The methods for actions in both the class and instance objects can be invoked with specific parameters:

For HTTP GET "class" actions: Resource.action([parameters], [success], [error])
For non-GET "class" actions: Resource.action([parameters], postData, [success], [error])
For non-GET instance actions: instance.$action([parameters], [success], [error])

Therefore, a potential approach could be:

var params = {product_id: 32342, variant_id: 536341};

Order.create({},params, function( resp ) {
  console.log("success");
});

The first parameter is crucial for inserting values into the URL parameters (e.g., /foo/:id would need {id: 324} as the first parameter)

Update:

An adjustment to the order of parameters was necessary:

var params = {product_id: 32342, variant_id: 536341};

Order.create(params,{}, function( resp ) {
  console.log("success");
});

Answer №2

After some reflection, I noticed that I forgot to include a second argument called POST-DATA.

Order.create(params, {}, function( resp ) {
  console.log("Operation successful");
});

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

The functionality of Angular animate becomes compromised when there is a conflict between predefined CSS states and transition states

Explore this example CSS code: /* animations at the start */ .error-animation.ng-enter { -webkit-transition: 0.5s linear all; transition: 0.5s linear all; opacity: 0; } ...

Displaying a submenu upon hovering within its designated CSS region

I'm encountering an issue with my submenu. It's supposed to appear when hovering over the parent menu li, but it also shows up when the mouse hovers over its area. Let's take a look at some images. First screenshot below shows that it works ...

React is unable to locate the component element within the DOM

I'm attempting to set the innerHTML for the div element with the ID of ed. Unfortunately, I am unable to access it once React has finished rendering. It seems that this is due to the render stages, as I am receiving a null value for the div element. W ...

Guide on incorporating d3 axis labels within <a> elements?

Issue at Hand: I am working with a specific scale var y = d3.scalePoint().domain(['a','b','c']).range([0,100]); I have successfully created an axis for this scale var y_axis = svg.append("g").attr("class", "axis").call(d3. ...

The issue with Internet Explorer failing to adhere to the restrictions set on maximum width and

I'm attempting to scale my images precisely using CSS: HTML: <div id="thumbnail-container"> <img src="sample-pic.jpg"/> </div> CSS: #thumbnail-container img { max-height: 230px; max-width: 200px; } In this scenario, ...

Unraveling HTML elements within a string using MongoDB: A step-by-step guide

Currently, I am in the process of creating a blog from scratch as a way to enhance my skills. The posts' content is stored as a long string in MongoDB with some random HTML tags added for testing purposes. I am curious about the conventional method fo ...

What is the best way to cancel a request within an HTTP-interceptor?

Within an application, I have established the following URL structure for the API: // public public/url-xyz // private dashboard/url-xyz To avoid unnecessary requests, what is the most effective method for canceling a request? My current approach involv ...

When I try to send data from my Node.js application to my MySQL database, the information does not

I am currently working on developing a registration and login page, where the user details are stored in a database for authentication during login. The registration button is meant to store user data in the database to complete the sign-up process. For t ...

Generating data for a table by choosing a row from another table through ng-repeat

One of the functionalities I am working on involves a table where users can select an option and have that selection populate another table called 'User Details'. The table is populated with data retrieved from an API call in the angular controll ...

Attempting to implement ajax for form submission, however finding that the $_POST array is coming back as empty

I'm attempting to send JavaScript arrays to a new page using Ajax. Although there are numerous questions on this topic on Stack Overflow, I have decided to implement Ajax in the following manner after examining various answers: var test = {}; test[& ...

What is the method of duplicating an array using the array.push() function while ensuring no duplicate key values are

In the process of developing a food cart feature, I encountered an issue with my Array type cart and object products. Whenever I add a new product with a different value for a similar key, it ends up overwriting the existing values for all products in the ...

Achieving closure by fulfilling the previously fulfilled promise once more

I have a situation while using $q in AngularJS. If I create a single promise that is already resolved, is it possible to resolve it again? I am unsure if this is feasible, but if not, is there any method by which I can resolve the same promise repeatedly ...

Customizing order and limit features in AngularJS

I have a collection of items that I need to organize into separate lists based on priority levels. items = [ {'type': 2, 'priority': 1, 'name': 'one'}, {'type': 1, 'priority': 2, 'na ...

Troubleshooting the issue with mocking API and creating a regular expression to match the dynamic part of a URL

I am struggling to create a mock for an API that includes dynamic parts in the URL. I attempted to use a regular expression, but it is not functioning as expected. The URL I am trying to mock is: https://example.com/programs/2fcce6e3-07ec-49a9-9146-fb84fb ...

Retrieve the content from a textarea and insert it into a different textarea with additional text included

Users can input HTML codes into a textarea named txtar1. A 'generate' button is available; Upon clicking the 'generate' button, the content of txtar1 will be transfered to another textarea named txtar2 with additional CSS code. Here&ap ...

What is the best way to retrieve multiple variables using Express.js on Node.js?

Trying to fetch Form data from an HTML page to a Node Js server. The HTML file is named index.html <body> <nav> <ul> <li> <a href="#" class="button add">Add Product</a> <div class="dialog" style="displ ...

Setting up numerous instances of TinyMCE for use

I am having trouble initializing two instances of tinymce on my webpage. Even after following the guidance provided in this particular thread, I am unable to get it working. Could it be possible that I need to introduce a timeout between initializing the ...

Angular ngView not displaying content on the page

To load a ngView page by clicking on a link, the html file does not appear as expected. Running the application directly without using localhost might be causing the issue. I simply opened index.html with Chrome browser, so it's possible that there i ...

Tips for expanding a script that relocates a logo into a navigation consisting of several unordered lists

I recently implemented a jQuery script to center a logo within my main navigation bar only when the screen width is above 980 pixels. It was working perfectly fine with a single unordered list, but as soon as I added more unordered lists within the nav, it ...

Change a Python string in the format 'min:sec' into a time object so it can be displayed correctly and sorted by the jQuery tablesorter

Currently, I am facing an issue where tablesorter is only working correctly on string representations of time that are below '25:00'. Any values above this are being sorted lower than strings like '24:12' or '09:24'. It seems ...