Sending multiple objects to the save() method in AngularJS $resource

The Operation Contract on the server is set up as follows:

[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/RegisterOrganization", RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
void RegisterOrganization(Organization organization, User admin);

On the client-side, a resource named RegisterOrganization has been created:

var RegisterOrganization = $resource(baseUrlService.getBaseUrl() + 'REST/Organization.svc/RegisterOrganization');

The issue arises when attempting to pass two objects as parameters like this:

RegisterOrganization.save(organization,admin)

An error 500 is returned when doing so. Any suggestions on how to resolve this problem?

Answer №1

Not sure about the specific server side function being called, but when using the save method with $resource, the first parameter should be query string parameters sent in the URL like this:

REST/Organization.svc/RegisterOrganization?organizationName=UniqueCompany&site=

The second parameter will need to be sent as JSON format. If your server side function expects data in JSON, make sure to adjust your code accordingly:

var data = angular.extend({}, organization, admin);
RegisterOrganization.save(null, data);

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

Are strings in an array being truncated by Firebug console log?

I have a unique function for logging messages to the firebug console that I'd like to share: // Just having fun with names here function ninjaConsoleLog() { var slicer = Array.prototype.slice; var args = slicer.call(arguments); console.lo ...

Hide the Modal Content using JavaScript initially, and only reveal it once the Onclick Button is activated. Upon clicking the button, the Modal should then be displayed to

While trying to complete this assignment, I initially attempted to search for JavaScript code that would work. Unfortunately, my first submission resulted in messing up the bootstrap code provided by the professors. They specifically requested us to use Ja ...

Selecting Elements with jQuery OR JavaScript

Question: jQuery attribute selector for multiple values I am facing a query regarding jQuery attribute selection. Here is the code snippet I have: $('input:radio[name=foo]').change(function() { blah(); }); $('input:radio[name=bar] ...

Navigating between pages using React-router-dom

Just implemented a simple navigation using react-router-dom. Managed to get it working with this.props.history.push('/pathName'); But I'm not entirely sure if my understanding and approach are correct. Any advice on correcting my mistakes wo ...

Generating pop-up upon loading with CSS3

I have searched through numerous threads and forums in the hopes of finding a solution, but I haven't been successful. My issue lies with triggering a popup on my website. I followed online tutorials to create a popup window, which I was able to do su ...

Enhancing one's comprehension of precompiling JavaScript

var foo=1; function bar(){ foo=10; return; function foo(){} } bar(); alert(foo); As I delve deeper into the inner workings of JavaScript running on the machine, I stumbled upon this code snippet. Despite my best efforts, I am perplexed as to why the ...

Enhance the progression bar using JavaScript

Is there a way to dynamically update a progress bar in HTML while a function is running? function fillProgressBar() { var totalIterations = 100; for (var i = 1; i <= totalIterations; i++) { //perform calculations progressBarWidth = (i/to ...

Error in Ajax autocomplete search functionality

I'm grappling with getting my autocomplete search to function properly. When attempting to retrieve data from my JSON array, it's just not cooperating. I'm still a bit green when it comes to this, but here's what my code looks like. Whi ...

ng-view is the culprit behind the website's fatal error

Encountering a "RangeError: Maximum call stack size exceeded" in the console while trying to recreate a basic routing example from w3schools. The crash seems to be linked to <div ng-view></div> in index.html. Despite making minimal changes from ...

Using AngularJS for posting data with $http.post() to a URL that differs from the project's base URL

Currently, I am working on building a mobile application in Cordova using AngularJS. My goal is to send data(parameters) through a POST request to a different project URL where my RESTful service pages are stored. Below is the code snippet that I have wri ...

Discovering the presence of a NAN value within a JSON string

Consider the following scenario: I have a function that receives jsonData in JSON format, and I want to validate the variable jsonData to check for NaN. How can I achieve this? function save() { var jsonData = getEnteredValue(); $.ajax({ ...

How can we parse the returned 'data' as HTML in JavaScript/jQuery to select more elements?

After receiving data from a webservice, it turns out that the data is just raw HTML without any XML headers or tags around it, but simply a piece of HTML code. <div class="Workorders"> <div id="woo_9142" class="Workorder"> <span ...

Attempting to update an AJAX field with the returned value, but it only updates after clicking away from it

Image of form utilizing AJAX & JS The current setup involves a maintainer that uses AJAX to update the "Calc" field in response to a number entered in the "Order No" field. The issue is that the "Calc" field does not update immediately after typing in the ...

Ways to implement a package designed for non-framework usage in Vue

Alert This may not be the appropriate place to pose such inquiries, but I am in need of some guidance. It's more about seeking direction rather than a definitive answer as this question seems quite open-ended. Overview I've created a package th ...

Tips for sending JSON data with OkHttp

I am currently working with OkHttp in Kotlin to send JSON data via a POST request to my REST API endpoint. Unfortunately, when I try to parse the request using JSONParser().parse(request), it results in a bad request error. It seems like there might be an ...

Trouble with passing data from action to reducer in Redux with React Native

As a newcomer to Redux, I'm encountering an issue while trying to make an API call in the Action and pass the data to the reducer. Although I can see the response from the API call, there seems to be a problem with sharing the data correctly with the ...

Click on the nearest Details element to reveal its content

Is there a way to create a button that can open the nearest details element (located above the button) without relying on an ID? I've experimented with different versions of the code below and scoured through various discussions, but I haven't be ...

Transformation of looks post a refresh

Initially, the CSS and appearance of the page look fine when I first open it (after clearing the cache). However, upon refreshing the page, a part of it changes (specifically, the padding direction of a div). This change occurs consistently with each refre ...

Failure to Include jQuery in Header.php File

After adding the jQuery library to header.php, I encountered an issue where index.php was unable to access the library. Surprisingly, when the library was referenced directly from index.php, access to the jQuery library worked without any problems. Here i ...

Utilizing ng-bind-html alongside ng-controller

Injecting insecure html into a <div> is part of my current task: <div class="category-wrapper" ng-bind-html="content"></div> The angularjs "code" in this html snippet ($scope.content) includes the following: <script type='text/ ...