Access information through the restful api using the angularjs service $resource

I am attempting to utilize the $resource service with the surveygizmo API.
Here is my code:

HTML :

<div ng-app="Survey">
<body>
<div ng-controller="SurveyCtrl">
    {{survey.data.title}}
</div>
</body>
</div>

My script :

angular.module('Survey', ['ngResource']);

function SurveyCtrl($scope, $resource) {
    $scope.surveygizmo = $resource('https://restapi.surveygizmo.com/v3/survey/:id',
        {id: '@id'},
        {get:{method:'JSONP', params: {'user:pass':'xxx@xxxx:xxxx', q:'angularjs', callback:'JSON_CALLBACK'}, isArray:true}});

$scope.survey = $scope.surveygizmo.get({id:xxxx}, function(survey) {
        alert('this is ok');
    }, function(err){
        alert('request failed');
    });
}

When I test it, the alert 'request failed' appears on my page. There is no JSON result displayed on the page, but I can see it in the firebug network menu.
Could I be missing something?
kalaoke

Answer №1

Although this question is quite dated, I wanted to offer some assistance. I am currently employed at SurveyGimzo and can confirm that we do provide support for JSONP, JSON, and XML formats. To request JSONP, you will need to explicitly specify it in the URL structure. Taking your example URL into consideration, it should appear as follows:

https://restapi.surveygizmo.com/v3/survey/:id.jsonp

By including JSON_CALLBACK as part of the ngResource parameters in your get action, you will receive an appropriately wrapped object in return.

I have been experimenting with a small AngularJS application utilizing SG REST API. Feel free to explore my GitHub repository https://github.com/sfisherGizmo/ang-app.

This information is intended to assist anyone else who happens to come across this in the future.

Answer №2

Survey Gizmo does not have JSONP support. The supported HTTP methods by Survey Gizmo are PUT, POST, DELETE. For more information, you can refer to the official documentation.

If they do support JSONP, it is not mentioned in their API documentation.

When changing from .get to .query, the request details include:

Request URL:https://restapi.surveygizmo.com/v3/survey/xxxx
Request Method:OPTIONS
Status Code:200 OK

If using .get instead, the response details show:

Request URL:https://restapi.surveygizmo.com/v3/survey/xxxx
Request Method:GET
Status Code:200 OK

However, the response is not callback-wrapped in JSONP format. Even though a response can be seen in Firebug network console, Angular cannot unwrap it due to the lack of JSONP response.

For AngularJS examples using ngResource, check out this link.

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

Enhancing the 'grunt build' process with partials for an AngularJS app

Is there a way to modify my Grunt file to ensure that it locates the partial views correctly? The grunt.js file I am using is the default one created when initializing an AngularJS application with Yeoman. It does not include any plugins or jQuery, just A ...

Encountering issues with React Apollo hooks after integrating React Native into the monorepo system

I am in the process of setting up a React web app and a React-native app within a monorepo using yarn workspaces. The web and controllers are functioning properly, allowing me to successfully execute graphql queries to my apollo-express server. However, up ...

What is the best way to insert a new item into an array that is nested within an object?

Currently, I am delving into the world of using $resource in angularjs and finding great examples in this answer AngularJS $resource RESTful example. Fetching and creating records is working fine, but now my challenge lies in adding a "section" to an exist ...

Error messages are appearing during the installation of mediasoup

Attempting to install via Command Prompt on Windows 7 64-bit following the command npm cache --force clean ...

What is the best way to record data while initiating a process in node.js?

In my latest project, I have implemented a function that spawns a process and requires logging specific information to the console. Here is an example of how this function is structured: function processData(number) { var fileName = settings.file || "de ...

Using JavaScript to implement form authorization in ASP.NET Web API

I am looking to revamp a business application by utilizing asp.net web api as the service layer and implementing JavaScript to interact with the web api for retrieving and displaying data. While I have a good grasp on how all the scenarios will function s ...

Tips for developing a dynamic game that adjusts to different screen sizes using Phaser 3

Recently, I've been on the hunt for a way to ensure my game adapts seamlessly to various screen resolutions when using Phaser 3. In the past, I achieved this with ease in Construct 2. However, I'm now curious to explore how best to implement thi ...

Creating a Node.JS application, developing an Express JS API, and handling errors

I am facing challenges while developing a REST API in Express.js and I am seeking assistance. Below is my Express.js code: router.get( '/apps/download/:downloadId', function ( req, res, next ) { const opts = Object.assign( {downloadId: re ...

Error encountered while running script across PHP pages

I have encountered an issue with the following code snippet. It runs perfectly fine in my initial PHP file, but when I attempt to use it in another file, the script does not seem to work as expected. Specifically, I do not receive any alert message from ...

Modal containing Jquery GalleryView

I am facing an issue with loading galleryView inside a modal. Even though using galleryView on its own works fine, I have been unable to make it work within a modal. Despite looking for solutions in previous posts, I couldn't find anything that fixed ...

Multiple file formats supported by Uploadify

I am trying to find a solution for having various file types in the jQuery plugin Uploadify. Consider this scenario: You want to open a file with a program of your choice. Starting with a default OS dialog, you can select different file types from a dropd ...

NetBeans is unable to analyze javascript files that are considered "large" (over 350 KB)

I have a significant JavaScript file (approximately 6 MB) that includes library API and documentation as shown below: /** * Function doc */ library.class.func=function(something){}; /** * Function 2 doc */ library.class.func2=function(something){}; ...

How can I export an array in Ajax/PHP to the user as a .txt file?

Currently, I am working on a PHP file named "php-1" that is responsible for generating an HTML page. This particular file requests input from the user and once the user clicks on a button labelled "getIDs" (it's worth noting that there are multiple b ...

Utilizing the power of JavaScript/JQuery to showcase a compilation of all input values within an HTML form

I'm struggling to showcase all the input values from my HTML form on the final page before hitting the "submit" button. Unfortunately, I am facing a challenge as the values are not appearing on the page as expected. Despite several attempts, the valu ...

Removing an unnecessary DIV element from an HTML Document

I have been working on a News application and am utilizing a web product to fetch News Headlines. When I request a NewsHeadline, the product sends back an HTML Code containing the News Headline. <div class="mydiv"> <script type="text/javascript ...

Can express-handlebars tags be utilized within an HTML script tag when on the client side?

For a while now, I've been facing a challenge. I'm in the process of building an application with express-handlebars and so far everything is going smoothly. The data that needs to be displayed on the webpages looks good thanks to the Helper func ...

Ways to create distance between repeated cards in a loop. My method involves utilizing ajax, jquery, and bootstrap

view image description here What is the best way to create some space between these closely aligned cards? .done((todos) => { todos.forEach(el => { console.log(el) $("#todo-list").append(` <d ...

Issue with PassportJS and Express 4 failing to properly store cookies/session data

I have a situation with my Express 4 app using Passport 0.3.2. I've set up a passport-local strategy, and it's successfully retrieving the user information when the /session endpoint is provided with a username and password. The issue arises whe ...

Encountering a NextJS error with head component

Trying to incorporate the head element into a NextJS page format has proven challenging. Despite consulting the official documentation, implementing next/head to add <head> has resulted in an error within the code block. Code: import Head from &apos ...

The issue with setting width using % in React Native is causing trouble

While working on my project using expo react native, I encountered an issue with a horizontal scrollview for images. When I style the images using pixels like this: <Image code... style={{width: 350}}/>, everything works fine. However, if I try to ch ...