John Polyzos
Posts: 0
Joined: Tue Nov 11, 2014 10:35 pm

How to invoke a service in JS?

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

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

How to invoke a service in JS?

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.

John Polyzos
Posts: 0
Joined: Tue Nov 11, 2014 10:35 pm

How to invoke a service in JS?

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

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

How to invoke a service in JS?

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.

Dongzhi Yang7528784
Posts: 0
Joined: Mon May 11, 2015 6:28 am

How to invoke a service in JS?

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});
Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

How to invoke a service in JS?

Hello Dongzhi,

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

Dongzhi Yang7528784
Posts: 0
Joined: Mon May 11, 2015 6:28 am

How to invoke a service in JS?

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

Dongzhi Yang7528784
Posts: 0
Joined: Mon May 11, 2015 6:28 am

How to invoke a service in JS?

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

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

How to invoke a service in JS?

You can use any custom JavaScript.

EJLD
Posts: 0
Joined: Sun Jun 08, 2014 11:03 pm

How to invoke a service in JS?

that helped me. thks

Return to “Issues”