Page 1 of 1

Service data not getting passed to javascript variable

Posted: Tue May 28, 2013 3:02 pm
by New Mobile Guy

I've done this in other parts of my app, but for some reason, it's not working with a new service.

Simply, I'm calling a service to retrieve a user's facebook friends. I want to put that information into a javascript variable, so I can access/parse later on via json.

For some reason, the javascript variable isn't getting created and set. I know the facebook service is working as I fill in a bunch of the data on the screen and I see it fine (i see a list of friends.) But I get a "friendData is not defined" error when I run the page, and the variable indeed is not set.

Any ideas? See attached screenshots for how I'm retrieving the data and the javascript. Image Image


Service data not getting passed to javascript variable

Posted: Tue May 28, 2013 3:44 pm
by maxkatz

"complete" is the standard jQuery callback: http://api.jquery.com/jQuery.ajax/ (search for complete). It gets passed the following:

code
Function( jqXHR jqXHR, String textStatus)
/code

it doesn't have access to friendData.


Service data not getting passed to javascript variable

Posted: Tue May 28, 2013 3:50 pm
by New Mobile Guy

Thanks. I may not be technical enough to understand your response. What would I exactly have to do to access the data from the service in javascript?

Would I adjust the javascript to somehow include the function you show?

Thanks (appreciate your patience here.)


Service data not getting passed to javascript variable

Posted: Tue May 28, 2013 4:08 pm
by Maryna Brodina

Hello! On service Complete event run the following code:
codelocalStorage.setItem("json_response", jqXHR.responseText);/code


Service data not getting passed to javascript variable

Posted: Tue May 28, 2013 4:31 pm
by New Mobile Guy

Works perfectly. Thanks!