abdul rashid
abdul rashid

Reputation: 750

AngularJS loading multiple items by AJAX call

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

Upvotes: 0

Views: 111

Answers (2)

JDurstberger
JDurstberger

Reputation: 4255

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

Upvotes: 0

Anand G
Anand G

Reputation: 3210

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.

Upvotes: 1

Related Questions