0

I have a listing page. WHere each listing has comments. I am using AngularJS routes to load the content http://example.com/#mycategory

The Problem: When user navigates to different category (Say: http://example.com/#mycategory22 ), If i want to load the comments inside every items listed (Below image), do i need to make ajax calls?.

According to the below example if i make ajax calls to load comments then it will be 3 ajax calls.

How to handle this problem.

Image showing different Items listed for a category;loaded using angularjs

abdul rashid
  • 730
  • 9
  • 21
  • I would create an ajax-call for every Category like `#/getComments?id=22` which loads all the comments of category 22 and add this comments as a list to the category-object and display them in an `ng-repeat` – JDurstberger Apr 17 '15 at 09:08
  • @SailorChibi In this case, if i have 20 items in a page, i need to send 20 ajax requests. – abdul rashid Apr 17 '15 at 10:02
  • Yes indeed. I don't know any other way to do this, except you already return your categories with a list of comments. – JDurstberger Apr 17 '15 at 10:04
  • @SailorChibi the problem is, if webserver response takes 1.5 seconds, then 20 Request will take 30 seconds to complete. – abdul rashid Apr 17 '15 at 19:57

2 Answers2

1

You can save your multiple ajax call by fetching all the comments at once using associated table id with comment. If I assume coupon is associated with comment so you should use coupon id to fetch associated comments. All you need to pass coupon id with request (URL) to fetch comments.

Rather using jQuery Ajax, use Angular $http service for this. You can checkout Processing $http response in service for help on this.

Community
  • 1
  • 1
Anand G
  • 3,130
  • 1
  • 22
  • 28
0

Here is what I would do:

  1. Get a list of Category-Id's from the Rest
  2. Make a request for EACH category (the response contains a few comments)

If a response takes ~ 1,5 seconds you can display a new category every 1,5 seconds. This seems short enough for not annoying the user, because it takes longer than 1.5 seconds to grasp one category and then there is the next one.

  1. add a "more..." button to your comments so the user can retrieve more comments for on category
  2. add a pager for your categories so the user can only see like 5 at a time
JDurstberger
  • 4,127
  • 8
  • 31
  • 68