Page 1 of 2

Got 'undefined' parse error for service

Posted: Mon Jul 14, 2014 8:05 am
by hb condo

I'm trying to setup / consume a Yahoo! RESTful service that has a callback and I am running into some issues:

  • Per the attached screenshot, the service test screen returns a response but is showing an error when attempting to automatically create a service response.

    Image

    To get around this, I manually created the Response.

    Image

  • When invoking the service, the Success event is not triggered but the Complete event is.

    How can I setup and consume this service? Any help is appreciated. Thanks.


Got 'undefined' parse error for service

Posted: Mon Jul 14, 2014 10:13 am
by Evgene Karachevtsev

Hello,

You get no JSON but JSONP in reply. You should remove request parameter callbackand and put in the configuration Data Type=JSONP Here you may find more info:
http://devcenter.appery.io/documentat...


Got 'undefined' parse error for service

Posted: Mon Jul 14, 2014 10:32 am
by hb condo

Hi, Evgene. Thank you for your reply. If I specify JSONP as the data type, then the callback parameter value is auto-generated which the RESTful service rejects. If I create a callback request parameter, then two callback values are passed. Is there a way to have a JSONP data type and a custom callback value? For this RESTful service, the callback must equal "YAHOO.Finance.SymbolSuggest.ssCallback".


Got 'undefined' parse error for service

Posted: Tue Jul 15, 2014 2:14 am
by Yurii Orishchuk

Hello,

Yes you can invoke "YAHOO.Finance.SymbolSuggest.ssCallback" in service "success" event.

So add JS event handler on success event for your service and populate it with following code:

pre

YAHOO.Finance.SymbolSuggest.ssCallback(data);

/pre

See details on scrren shot: http://prntscr.com/42s0in/direct

Regards.


Got 'undefined' parse error for service

Posted: Tue Jul 15, 2014 3:53 am
by hb condo

Thanks for the screenshot, Yurii. I added the code but I'm not sure how to implement the actual callback function. Can you advise on the next steps on how to work with the data parameter?


Got 'undefined' parse error for service

Posted: Tue Jul 15, 2014 4:16 am
by Yurii Orishchuk

If you don't need invoke "YAHOO.Finance.SymbolSuggest.ssCallback" event handler you can work with returned data directly in the "success" event handler.

For example:

pre

//This line of code will print to the debug console. Please check it out to see what is in your "data" returned object.
condole.log(data);

alert(data);

alert(data.length);

/pre

Also if it will not help please specify what exactly you want to do.

Thanks & regards.


Got 'undefined' parse error for service

Posted: Tue Jul 15, 2014 5:29 am
by hb condo

Thank you for the quick reply. Below is how I call the service in jQuery, how can I incorporate this into Appery?
code
$.ajax({
type: "GET",
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "YAHOO.Finance.SymbolSuggest.ssCallback",
data: {
query: "msft"
},
url: "http://autoc.finance.yahoo.com/autoc"
});
/code
code
YAHOO.Finance.SymbolSuggest.ssCallback = function (data) {
alert(data.ResultSet.Result);
}
/code


Got 'undefined' parse error for service

Posted: Tue Jul 15, 2014 4:49 pm
by Kateryna Grynko

Hello,

You can add this code to custom realization of Generic service: http://devcenter.appery.io/documentat...


Got 'undefined' parse error for service

Posted: Tue Jul 15, 2014 10:21 pm
by hb condo

We have tried the Generic service but we are having trouble getting it to work. Could you provide guidance based on the js provided above how we would setup a generic service?

Ideally, we would like to use a REST service configuration so could you be able to answer part of my question of Is there a way to have a JSONP data type and a custom callback value?


Got 'undefined' parse error for service

Posted: Wed Jul 16, 2014 2:49 am
by Yurii Orishchuk

Hello,

Please follow the solution below:

1 Create generic service http://prntscr.com/434glf/direct.

2 Click "Add custom implementation"

3 Choose "new javascript" with name "genericService1JS". http://prntscr.com/434h6f/direct

4 Use following code in "JS" implementation:

pre

//Note replace "genericService1JS" with your value.
Appery.genericService1JS = Appery.createClass(null, {

Code: Select all

 init : function(requestOptions) { 
     this.__requestOptions = $.extend({}, requestOptions); 
 }, 

 process : function(settings) { 

     if(!self.YAHOO || !YAHOO.Finance || !YAHOO.Finance.SymbolSuggest) 
         self.YAHOO = {Finance: {SymbolSuggest: {} } }; 

     $.ajax({ 
         type: "GET", 
         dataType: "jsonp", 
         jsonp: "callback", 
         jsonpCallback: "YAHOO.Finance.SymbolSuggest.ssCallback", 
         data: { 
             query: "msft" 
         }, 
         url: "http://autoc.finance.yahoo.com/autoc" 
     }); 

     YAHOO.Finance.SymbolSuggest.ssCallback = function (data) { 
         alert(data.ResultSet.Result); 

         settings.beforeSend(settings); 

         settings.success(data.ResultSet.Result); 

         settings.complete('success'); 
     } 

 } 

});

/pre

Regards.