- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have to read several URL using JSON. I am using for looping to read each URL.
The problem is the getJSON result is always different base on URL respond.
Is it any way to wait for looping until getJSON process is finished ?
Thanks,
Muhammad
input_string = window.localStorage.getItem("all_id"); var parts = input_string.split(','); for (var t=0; t<parts.length; t++){ url = base_url + "products/" + parts+ '/reviews?' + ck + '&' + cs; $.getJSON(url, function(data){ $.each(data, function (index, value2) { review_detail = ''; for (var i = 0, len = value2.length; i < len; i++) { star_number = get_star(value2.rating); //alert (star_number) review_detail += star_number + "<br>"; review_detail += value2.review + "<br>"; review_detail += value2.reviewer_name + "<br>"; //alert(review_detail); } }); }); }
- Tags:
- HTML5
- Intel® XDK
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you are trying to execute a specific action after every successful getJSON reponse, I recommend implementing a success function that calls the appropriate function wit the appropriate parameters. You won't need a for loop as you would be recursively calling your function that performs the necessary actions per the url.
You can learn more about the callback methods associated to getJSON at http://api.jquery.com/jquery.getjson/.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page