Page 2 of 3

How to invoke a service in JS?

Posted: Tue Nov 11, 2014 10:35 pm
by John Polyzos

Hello! I'm sorry to disturb you.. I'm trying to invoke a service with input and output variables too. the output of the service is like this:

{
"account":0,
"message":"mpla mpla"
}

i have tried this code:

copied from a reply in the current topic

var onSuccess = function(data){
console.log(data);
var newData = data.data;
console.log("dataitems = " + newData.length);
//Iterate through data items:
for(var i = 0; i < newData.length; i++){
var id = newData.id;
alert("id[" + i + "] = " + id);
}
};

in this section I'm trying to pass the variables from the components of the page and manage the output variables of the service.
I have 5 input variables and 2 output variables.

Code: Select all

 GetSeamanVerification.execute({body: 
          {"FLAG":"account_exists", 
           "FIRSTNAME":Appery('sFirstname').val(), 
           "LASTNAME":Appery('sLastname').val(), 
           "MOBILE":Appery('sMobile').val(), 
           "BDATE":Appery("sDOB").getAttr("defaultDateValue"), 
          },success: {success: onSuccess}}); 

Thank you in advance!

Best regards


How to invoke a service in JS?

Posted: Wed Nov 12, 2014 4:35 am
by Yurii Orishchuk

Hi John,

Looks ok, instead of:

pre

&#47;&#47;success should be a function&#46; And you have here object&#46;
success: {success: onSuccess}

/pre

So try this code:

pre

GetSeamanVerification&#46;execute({body:
{"FLAG":"account_exists",
"FIRSTNAME":Appery('sFirstname')&#46;val(),
"LASTNAME":Appery('sLastname')&#46;val(),
"MOBILE":Appery('sMobile')&#46;val(),
"BDATE":Appery("sDOB")&#46;getAttr("defaultDateValue"),
},success: onSuccess});

/pre

Regards.


How to invoke a service in JS?

Posted: Wed Nov 12, 2014 8:22 pm
by John Polyzos

Dear Yurii thank you for your response,
I tried the code you suggested but when I try to debug the program i get

"Uncaught TypeError: Cannot read property 'length' of undefined VM4262:337onSuccess VM4262:337fire jquery-2.1.1.js:3073self.fireWith jquery-2.1.1.js:3185done jquery-2.1.1.js:8251(anonymous function)"

Any ideas?
Thank you
Best regards


How to invoke a service in JS?

Posted: Thu Nov 13, 2014 3:30 am
by Yurii Orishchuk

Hi Jogn,

It seems to be problem in your success event handler.

See details on screen shot: http://i.imgur.com/bNegPkC.png

So please take a look in console to see what exactly stored in your "data" success parameter.

Regards.


How to invoke a service in JS?

Posted: Sat Jun 06, 2015 3:41 am
by Dongzhi Yang7528784

Hi Yurii,

I have the following code and I want to navigate to a new page when the service succeeded. But after success it doesn't take me to the new page. I wonder if Apperyio.navigateTo is working in this senario? thanks!

Code: Select all

var onSuccess=function(data){ 
  console.log("AddTaskSuccess"); 
  console.log("NavigateToDoTodayStartPage"); 
  Apperyio.navigateTo('doTodayStartPage', {});   
 }; 
 doTodayDB_Task_AddNewTask.execute({success:onSuccess});

How to invoke a service in JS?

Posted: Sat Jun 06, 2015 4:45 am
by Evgene Karachevtsev

Hello Dongzhi,

Could you check are there any errors in console? This should help:
http://devcenter.appery.io/documentat...


How to invoke a service in JS?

Posted: Sat Jun 06, 2015 6:55 am
by Dongzhi Yang7528784

Another question, can I create function for before send, complete and error in the following way?

var onBeforeSend=function(data){};
var onComplete=function(data){};
var onError=function(data){};

Thanks in advance


How to invoke a service in JS?

Posted: Sat Jun 06, 2015 10:32 am
by Dongzhi Yang7528784

Evgene,

In my case,the service is successful and it gets my the expected results.
Only the navigateto doesn't work.
I used Google chrome to montor errors but there are nt any
.
Can navigateto be used inside the onsuccess function
?
Dongzhi


How to invoke a service in JS?

Posted: Sat Jun 06, 2015 11:12 am
by Alena Prykhodko

You can use any custom JavaScript.


How to invoke a service in JS?

Posted: Sat Feb 13, 2016 5:43 am
by EJLD

that helped me. thks