Sending a raw XML data through AngularJS's $resource service (version 1.2.x)

Trying to utilize AngularJS's $resource to send XML via POST to an API, I'm uncertain about how to pass the data that needs to be sent.

This is my current setup:

    "Cart": $resource("http://........../api?ws_key=*********", {
        ws_key: ws_key
    }, {
        save: {
            method: "POST",
            isArray: false,
            headers:{
                'Content-Type':'raw; charset=UTF-8'
            }
        }
    })

If sending a simple string (xml), where exactly should it be passed?

Answer №1

You have the option to utilize transformRequest, which is set by default to convert the data being passed through into JSON format.

"Cart": $resource("http://........../api?ws_key=*********", {
    ws_key: ws_key
}, {
    save: {
        method: "POST",
        isArray: false,
        transformRequest: function transformDataToXml(data, headersGetter) { /* ... */}
        headers:{
            'Content-Type':'application/xml; charset=UTF-8'
        }
    }
})

After that,

card.$save("<tab>content</tag>"); 

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

iframe-based cross-site file upload

I created an image uploading API and implemented a jQuery plugin that utilizes an iframe for the upload process. However, due to the API's domain being different, I am unable to retrieve the return data from the iframe. Is there a solution to accessin ...

Avoid displaying the outcome until after the browser is refreshed using AJAX

I am facing an issue with my insert query through ajax. It works correctly, but when I reload the browser, the result disappears from the div section. However, if I insert the form through ajax again, the result shows up. In my setup, there is a file name ...

Using Local Storage with JavaScript and AngularJS

I have stored some data in local storage within the index.js file using JavaScript: var account = { name: name, email: email }; // Converts the object literal to a JSON string account = JSON.stringify(accoun ...

Tips for utilizing the Raycaster in tandem with a CombinedCamera?

When trying to implement a Raycaster for selection, I encountered an issue where it worked fine with a PerspectiveCamera but not with a CombinedCamera. It appears that the Raycaster does not support CombinedCamera, so I made some modifications in the thre ...

What is the best way to implement ajax loading on scroll?

I need to implement lazy loading for multiple ajax pages on my website. I want the ajax content to load dynamically as the user scrolls down the page, similar to infinite scroll or lazy image loading. $('.lazy_content').on('load', fu ...

Using jQuery, retrieve all the values in the table data cells of a specific row

{% set i = 0 %} {% if user_papers|length > 0 %} {% for user_paper in user_papers %} {% set u_user = user_paper.user %} {% set i = i+1 %} {% set i ...

What is the best method to select a row using Selenium in Java?

While performing my manual test, I was successfully able to select the "HTTP.BROWSER" row with just a single click. Below is a screenshot of the webpage: https://i.sstatic.net/uNmgT.png The HTML code snippet <ul> <li ng-repeat="d in $ctrl. ...

Struggling to make ng-repeat function properly within an AngularJS controller when working with arrays

I am having trouble with my code. The ng-repeat in my AngularJS app is displaying blank. Can someone help me figure out why? Thanks in advance, Stephanie <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/aja ...

Tips for preventing the use of eval when invoking various functions

Here's a snippet of code I've been using that involves the use of eval. I opted for this approach as it seemed like the most straightforward way to trigger various factory functions, each responsible for different web service calls. I'm awa ...

Extracting the value of an HTML element from a string variable in AngularJS

I am facing an issue with my application where the content of an HTML element is received as a template from the server. I am attempting to assign this template, which is essentially a string, and have the variables within the template linked to the contro ...

Encountering a problem with configuring webpack's CommonsChunkPlugin for multiple entry points

entry: { page1: '~/page1', page2: '~/page2', page3: '~/page3', lib: ['date-fns', 'lodash'], vendor: ['vue', 'vuex', 'vue-router'] }, new webpack.optimize.C ...

Understanding JavaScript Prototypal Inheritance within ES5 Classes

I've been working on creating an XMLHttpRequest interceptor for Angular, encountering a roadblock when trying to intercept a third-party library that uses the XMLHttpRequest API. Although the solution below is functional, I've run into issues wit ...

Click events not triggering in Ng

Hey there, I'm just starting out with Angular today and running into some issues trying to bind an event. Here's what I've been working on so far - I have all my scripts loaded in the HTML page: <script src="Scripts/jquery-1.9.0.js">& ...

FireFox is unresponsive to OPTIONS requests

I have a webpage that is accessed through HTTP. The client-side code is making AJAX requests for authorization to the same domain, but using HTTPS, which causes CORS issues. When using FireFox, the request looks like this: // domains and cookies are chang ...

Unable to trigger ng-click event on an element that has been compiled in a controller

Is there a way to utilize $compile in order to enable ng-click functionality on a specific code block? Currently, my code is set up to display a suggestion box when certain event parameters are met. However, I am looking to give users the ability to hide t ...

I'm facing an issue while attempting to fetch an API. I'm not certain what is lacking in my code, but the console is showing an error on

While troubleshooting my code, the console pointed out an error in line 15 of my javascript. However, I am having trouble identifying what exactly is causing the issue. The button I designed in HTML does not seem to be fetching the API facts as intended, ...

A guide on transferring data from JavaScript to HTML and efficiently directing it to a Laravel 5 controller

Recently, I have been exploring different ways to connect Javascript with HTML and interact with PHP. Although I am comfortable using plain PHP to send or retrieve data from a PHP backend, I decided to dive into Laravel5 as my PHP framework. So far, it has ...

JavaScript: Invoking a function within another function via an HTML document

I have a unique scenario where I have one function inside another and I am looking to call the inner function from an HTML document. <head> <meta charset="utf-8"> <title></title> <link rel="stylesheet" href="style.css"> ...

How can we determine if a 2D array contains a specific string using javascript?

I am currently working on a script to locate the horizontalWord string within a two-dimensional array. While my function for finding verticalWord strings is running smoothly, I am encountering some difficulties with the horizontalWord string. If you have ...

I noticed that my regular expression is functioning correctly on regex101, but for some reason, it's

My search works perfectly on regex101 using this link: https://regex101.com/r/z8JCpv/1 However, in my Node script, the third matched group array[2] is returning not only the matching text but also everything following it. An example line from the source ...