REST Calls with callback function

How do I make a REST call in enyo 2.7?
REST call returns me a callback function how do i handle it.

Comments

  • Can you provide a little more detail on your issue?
    Below you can see the way I make REST (AJAX) calls with my code in Enyo 2.7. The two examples below do the same just the second makes calls to other function (processResponse, processError) to handle the next phase of the call.

    Hope this helps. If not provide a little more detail and I will see if I can better help.
    
    var Ajax = require('enyo/Ajax');
    
    myAjaxCall: function() {
        var ajax = new Ajax({
            url: "http://url-to-my-webservice",
            method: "GET"
        });
    
        ajax.go();
        ajax.response(this, function (inSender, inResponse) {
            console.log(inResponse);
        });
        ajax.error(this, function  (inSender, inResponse) {
            console.log(inResponse);
        });
    },
    
    OR
    
    myAjaxCall: function() {
        var ajax = new Ajax({
            url: "http://url-to-my-webservice",
            method: "GET"
        });
        ajax.go();
        ajax.response(this, 'processResponse');
        ajax.error(this, 'processError');
    },
    processResponse: function(sender, res) {
        console.log(res);
    },
    processError: function(sender, res) {
        console.log(res);
    }
    
    Link to Enyo Ajax sample:
    AjaxSample.js
  • edited October 2016
    sry for late reply

    In enyo 2.5 i used to make rest calls as below

    var request = new enyo.JsonpRequest({
    buildUrl: function () {
    return url;
    }
    });
    request.go();

    and i would get response as callback({jsonData}) which calls a function in my enyo app for further processing

    but in enyo 2.7 i get a error as callback is undefined

    var JsonpRequest = require('enyo/JsonpRequest ');
    var request = new JsonpRequest({
    buildUrl: function () {
    return "restUrl";
    }
    });
    request.go();
  • Are you requiring the correct Jsonp module?
    Looking in the Jsonp example, they have the following require...
    JsonpRequest = require('enyo/Jsonp'),
    Take a look at the JsonpSample and see if it helps.
    If you are still having issue, then maybe you can setup a jsfiddle with your code so we can take a look and determine the issue.
    Thanks


    Freddy
Sign In or Register to comment.