Best practices for creating a ColdFusion service for transmitting JSON data and receiving it through AngularJS

I've been facing a tough situation working all day :(. Any help would be greatly appreciated.

My website needs to use the $http provider to call a ColdFusion file from another domain. Let's assume the link to the cfm file is:

http://xample.com/getStockCodesTest.cfm


This is an example of a ColdFusion file:

<cfcontent
type="application/json"
/>
{
    "items": [
        {
            "StockCode" : { "col": "Stock Code", "value": "0231" },
            "Qty" : { "col": "Qty", "value": "DS" },
            "QtyOn" : { "col": "Qty On", "value": "Branch" },
            "QtyVal" : { "col": "Qty Val", "value": "200" },
            "ReleasedDate" : { "col": "Released Date", "value": "0" },
            "S" : { "col": "S", "value": "0" },
            "Description" : { "col": "Description", "value": "adfasdf" },
        }
    ]
}

This is the angular code (written in coffeescript)

ajax = $http {
        url: 'http://xample.com/getStockCodesTest.cfm'
        method: 'JSONP'
        params: {
            callback: "JSON_CALLBACK"
        }
    }
    ajax.success (data, status, headers, config) ->
        console.log data

However, when checking Firebug, it always returns an error:

So, what is the correct way to write a test ColdFusion with content json like that and use AngularJS to capture it on my website :(

Answer №1

I'm a little unsure about the specifics of your question. However, what I do know is that the error you are experiencing is due to having invalid JSON code.

The culprit appears to be that unnecessary comma. By removing it, you will have valid JSON code.

Answer №2

In order for a JSONP call to function properly in AngularJS, it is necessary to enclose your JSON data within the input function name. Failure to do so will result in an error message.

Below is an example of a JSONP response:

/xxx.cfm?_jsonp=angular.callbacks._0 --- request

// The expected response should resemble this - a function specific to your ColdFusion
angular.callbacks._0([{"StockCode" : { "col":...

Ensure that you follow this format for it to work successfully.

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

What is the best way to create a global variable using jQuery?

Is it possible to pass the value of a_href = $(this).attr('href'); function globally and set a_href as "home"? var a_href; $('click a').on('hover', function(e){ a_href = $(this).attr('href'); ...

Angular 8 combined with Mmenu light JS

Looking for guidance on integrating the Mmenu light JS plugin into an Angular 8 project. Wondering where to incorporate the 'mmenu-light.js' code. Any insights or advice would be greatly appreciated. Thank you! ...

Is it possible to utilize a map in Python or incorporate other advanced functions to efficiently manage indices?

When working with higher order functions in JavaScript, we have the ability to access the element, index, and iterable that the function is being performed on. An example of this would be: [10,20,30].map(function(element, index, array) { return elem + 2 ...

Is it possible to transform protobuf wireformat into JSON using only a message descriptor?

Typically, the process of converting a protobuf message from wire format to JSON involves unmarshalling the wire format into a proto.Message, which is a concrete Go type (generated by protoc-gen-go), and then using the protojson package to convert it to JS ...

Initializing select element with ng-init

This is the code snippet I have implemented for ng-init: <select ng-model="yourSelect3" class="form-control" ng-init="yourSelect3=requirements.Item2[0]" ng-options="yourSelect3.StateName for yourSelect3 in requirements.Item2"> &l ...

I am looking to retrieve data from the Graph API JSON and gradually refine my search to achieve successful

I am looking to retrieve data from the "fb_page_categories" endpoint, which provides an array of categories a page can be categorized under. The format for this request is as follows: GET graph.facebook.com /fb_page_categories? Once this request is mad ...

Utilizing various methods of interaction in asp.net

Imagine I have two webpages, namely page1.aspx and page2.aspx. The scenario is as follows: in page1.aspx, I use window.open() in JavaScript to call page2.aspx and pass a query string. Then, in page2.aspx (the child page), I need to gather user informatio ...

Using JavaScript to generate JSON data in a plain text format rather than using HTML

I have a snippet of code that retrieves the user's location every 5 seconds. <div id="geo" onLoad=""></div> <script> function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPo ...

What is the process for transmitting a JSON object via POST in PHP?

I am trying to send a JSON object with a POST request in PHP. However, I have attempted various methods without success. Below is the code I have tried: function get_user_post_other_count($user_id, $call_for) { $params = array('user_id' =&g ...

Sending arrays' values in JavaScript

Here is a list of different groups to choose from: <select multiple="multiple" name="groups[]" id="groups[]" class="myclass"> <option value="1">Employees</option> <option value="2">Vendors</option> <option valu ...

Encountering difficulties when trying to showcase JSON data using jQuery DataTables

As a beginner in jquery datatables, I am faced with the challenge of handling JSON data returned from the server in a specific format: { "links": [ { "rel": "self", "href": "http://hostname:port/state/city/1" } ], "name1": "value ...

Issue with filtering (ngRepeat) in a table across multiple columns is not fully functional

I am looking to apply a filter on my table that is created using ng-repeat. <tbody> <tr ng-repeat="x in contact.listeContacts | filter:contact.searchText track by $index"> <td> &l ...

Troubleshooting problem of slow performance with ng-options when utilizing a custom filter within ng-repeat

I'm experiencing a performance challenge. I'm utilizing custom filters within ng-options nested under ng-repeat. Here's the snippet of code: <div ng-repeat="item in items"> <select ng-model="User[item.id]" ng-options="translatedKe ...

Switch up the images based on the JSON response that is received

When receiving a JSON response, I am using the item details to populate a menu grid by utilizing an adapter. So far, I have successfully loaded all the item details such as ImageURL, Description, and Price. However, I encounter an issue when loading the is ...

Issue 500 encountered while implementing VB.NET with jQuery AJAX

Having trouble populating a select option using jQuery ajax, and I could really use some assistance! Encountering the following error: Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:20440/admin ...

ReactJS tweet screenshot capture

Currently seeking a solution to capture a tweet screenshot, store it in a PostgreSQL database, and display it on my ReactJS webpage using Typescript. I have been utilizing react-tweet-embed for displaying the tweet, but now I require a method to save the i ...

Angular - Dividing Values within Input Arrays

In the input field available to users, they can enter multiple inputs separated by commas. <div class="container"> Enter your values:<input type="text" multiple #inputCheck> <input type="submit"(cli ...

jQuery fails to hide DIVs when jQuery.show() has been utilized in a previous event

I've always considered myself pretty proficient in jQuery, but this particular issue has me stumped. Essentially, I have a click event that should hide one DIV (a placeholder) and show two others (an input section and control buttons section). However ...

Page redirects automatically after AJAX call

I'm a beginner when it comes to using AJAX and I am trying to delete a student from a list through an AJAX request. I want the response of the request to be displayed on the same page within a specific div, but instead, the response keeps redirecting ...

I find myself pondering the reason behind my inability to overwrite the jquery function onRegionOver. The contents of the WAMP index.html file can

I'm curious about why I'm having trouble overriding the jquery function onRegionOver. Below is the code snippet from my WAMP index.html file. Can anyone suggest how I might use the WAMP console to troubleshoot this issue? I'm attempting to g ...