Saul Galloway
Posts: 0
Joined: Wed Apr 30, 2014 7:52 am

Referencing the query object in JS query

I made a text field and a button, and on the button click event I run JS

pre
getQuestions.execute({data:{where: '{"_id":"53620e12e4b058d902d3f58b"}',
success:function(data){
alert("success! "+data);
},
error:function ( jqXHR, textStatus, errorThrown ) {
alert("error!");
}

}});
/pre

The getQuestions query is mapped to the text field

When I click the button I get pop up "Success!undefined" then pop up "error!" then the query result is placed into the text box as expected.

How do I reference the returned query object in JS?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Referencing the query object in JS query

Hello Saul,

use:
"data":{"where": '{"id":"53620e12e4b058d902d3f58b"}'}
instead of:
data:{where: '{"id":"53620e12e4b058d902d3f58b"}'

Saul Galloway
Posts: 0
Joined: Wed Apr 30, 2014 7:52 am

Referencing the query object in JS query

Great, getting there...:-)

pre
getQuestions.execute({"data":{"where": '{"_id":"53620e12e4b058d902d3f58b"}'},
success:function(data){
// do some processing in here
// now return the processed data
return(data);
// this does not work either
// return("success handler called");
},
error:function ( jqXHR, textStatus, errorThrown ) {
alert("error!");
}
});
/pre

If I take out my success handler the data comes back and populates the bound text box as expected, and the success handler is called (if I put an alert in there, that alert gets run before before the data return), but my syntax for the return is clearly incorrrect.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Referencing the query object in JS query

It isn't correct using of service's events.
Look answer here: https://getsatisfaction.com/apperyio/...

Return to “Issues”