How to get data back from server?

JDX7913
Tera Guru

When a user click on a button my client script will take that info and sent it to the server to do some calculation. After that what do I put in the client script to pull the result back from the server?

 

This is what I have so far.

HTML:

<button class="button" ng-click="c.redirect(name)">Submit</button>

Client:

c.redirect = function(name){
  c.server.get({passVal:name}).then(function(r){});
}

Server:

if(input){
 var find = input.passVal;
 //Do stuff

 returnResult = //done <---set result to returnResult
}
else{
 var returnResult = {};
}

 

1 ACCEPTED SOLUTION

Dylan Mann1
Giga Guru

Set a property in your data object to the value that you want returned and you'll then be able to access it in your then() function. Try something like this:

Client:

 c.redirect = function(name){
  c.server.get({
    action: yourAction,
    passVal: name
  }).then(function(r){
     c.result = c.data.returnResult;
  });
}

Server:

if(input && input.action === "yourAction"){
 var find = input.passVal;
 //Do stuff

 data.returnResult = //done <---set result to returnResult
} else {
 data.returnResult = {};
}

You might not need the whole action part, but whenever using server.get I always add an action to my custom input object.

Let me know if this helps,

Dylan

View solution in original post

3 REPLIES 3

Allen Andreas
Administrator
Administrator

You'd most likely need to store that information in a variable and then pass that back to the form, I assume that's what you want to do.

So you'd g_form.setValue('fieldnameonform', variablename);


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Dylan Mann1
Giga Guru

Set a property in your data object to the value that you want returned and you'll then be able to access it in your then() function. Try something like this:

Client:

 c.redirect = function(name){
  c.server.get({
    action: yourAction,
    passVal: name
  }).then(function(r){
     c.result = c.data.returnResult;
  });
}

Server:

if(input && input.action === "yourAction"){
 var find = input.passVal;
 //Do stuff

 data.returnResult = //done <---set result to returnResult
} else {
 data.returnResult = {};
}

You might not need the whole action part, but whenever using server.get I always add an action to my custom input object.

Let me know if this helps,

Dylan

Thank you for the help.