New Mobile Guy
Posts: 0
Joined: Tue Jan 29, 2013 9:09 pm

Service data not getting passed to javascript variable

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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Service data not getting passed to javascript variable

"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.

New Mobile Guy
Posts: 0
Joined: Tue Jan 29, 2013 9:09 pm

Service data not getting passed to javascript variable

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.)

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Service data not getting passed to javascript variable

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

New Mobile Guy
Posts: 0
Joined: Tue Jan 29, 2013 9:09 pm

Service data not getting passed to javascript variable

Works perfectly. Thanks!

Return to “Issues”