Thank you very much for your reply Mr.Jason.

Can you also write a callback function for the example you provided
above. This will help me a lot!. Iam new to JSON.
The callback function should be able to print the fetched content for
each friend....



On Jun 28, 4:19 am, Jason <[EMAIL PROTECTED]> wrote:
> It looks like you're asking two questions here:
> 1) How do I request data for multiple people with a single request?
> 2) Why is the ID incrementing not working?
>
> My answers:
>
> 1) You skipped most of your makePOSTRequest code but this is how I
> would change it. You should be able to retrieve the data for all of
> your friends with a single request instead of firing off a request for
> each friend. The snippet below assumes that the data that you're
> storing on your back-end is keyed by the person ID:
>
> /* ************************************** */
> var postData = {
>   people: []
>
> };
>
> this.viewerFriends.each(
>   function(person) {
>     postData.people.push(person.getId());
>   }
> );
>
> var params = {};
> params[gadgets.io.RequestParameters.METHOD] =
> gadgets.io.MethodType.POST;
> params[gadgets.io.RequestParameters.POST_DATA] =
> gadgets.io.encodeValues(postData);
> params[gadgets.io.RequestParameters.CONTENT_TYPE] =
> gadgets.io.ContentType.JSON;
> params[gadgets.io.RequestParameters.AUTHORIZATION] =
> gadgets.io.AuthorizationType.SIGNED;
> ...
> gadgets.io.makeRequest(url, callback, params);
> /* ************************************** */
>
> Notice that I'm expecting a JSON object back. This way, I can create
> an object for each person on the server, store it in an array, and
> send this back to the client as a JSON-encoded string so I can access
> all of the friend data in my callback. Please let me know if you have
> any questions on how this works. (For the record, you can also format
> an XML response and use gadgets.io.ContentType.DOM if you prefer.)
>
> 2) I'm a bit confused on why you're using incrementing IDs. This
> assumes that you know the number of friends to begin with -- if you
> create 10 divs statically with IDs friend1, friend2, ..., friend10
> then you can only show 10 friends. I would create these divs
> dynamically instead. You can still assign them an ID if you wish, but
> you don't need to:
>
> // iterating through the number of objects returned in the JSON/DOM
> result above:
> var newDiv = document.createElement();
> newDiv.id = 'friend'+i;
> newDiv.innerHTML = ...
> document.appendChild(newDiv);
>
> As for your problem above, I'm not sure but it may have been due to:
> increment=("ifriends"+i); -- should this be increment=("friends"+i);
> instead?
>
> I hope this helps. Let me know if you have any questions.
>
> - Jason
>
> On Jun 25, 1:06 am, Prithvi Raj <[EMAIL PROTECTED]> wrote:
>
> > I need to increment <divid="friends0"> ....... <div
> > id="friends25"> .. and so on...
> > That is... for every Friend of the user. Iam fetching some data from
> > my server. And display them.
> >  I want to create a uniquedivID for each of the html content fetched
> > for each user. But there is some problem in iterating thediviDs...
> > there problem is in the statement
> > document.getElementById(increment).innerHTML = html;  where
> > 'increment' is a variable containing "friends"+i. where i iterates....
> > What should i do to make this code work??
>
> > Here is the code i have used.
> > ------------------------------------------------------
> > var i=0;
> > var increment="friends"+i;
>
> >  viewerFriends.each(function(person) {
>
> >  makePOSTRequest();
>
> > function makePOSTRequest();
> > {
> > .
> > .
> > .
> > .
> >    gadgets.io.makeRequest(url, reqpost, params);
> >  }
>
> >   function reqpost(obj) {
>
> >       var str = obj.text;
> >       var html =  str.substr(0,400);
>
> > document.getElementById(increment).innerHTML = html;      // i tried
> > even (""+increment+"") and without assigning it to a variable i tried
> > directly also ("friends"+i)
>
> >   };
>
> > i=i+1;
> > increment="ifriends"+i;
>
> > });
>
> >  ---------------------------------------
> > if this is not a proper way. What all the other ways can i fetch data
> > from my server for each person???
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Orkut Developer Forum" group.
To post to this group, send email to opensocial-orkut@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/opensocial-orkut?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to