我还在学习Angular JS并且让这个控制器使用不同的参数向lastfm api发出两个ajax请求.我想知道每个请求何时完成,以便我可以显示两个请求的加载指示器.我已经研究了它并阅读了有关承诺和$ q服务但是无法理解如何将其融入到这里.有没有更好的方法来设置它?以及如何知道每个请求何时完成.谢谢.
angular.module('lastfm')
.controller('ProfileCtrl', function ($scope, ajaxData, usersSharedInformation, $routeParams) {
var username = $routeParams.user;
//Get Recent tracks
ajaxData.get({
method: 'user.getrecenttracks',
api_key: 'key would go here',
limit: 20,
user: username,
format: 'json'
})
.then(function (response) {
//Check reponse for error message
if (response.data.message) {
$scope.error = response.data.message;
} else {
$scope.songs = response.data.recenttracks.track;
}
});
//Get user info
ajaxData.get({
method: 'user.getInfo',
api_key: 'key would go here',
limit: 20,
user: username,
format: 'json'
})
.then(function (response) {
//Check reponse for …Run Code Online (Sandbox Code Playgroud) 我是ajax/php的新手,所以我想找出最好的方法.
我有一个sql数据库填充1500个项目,我正在加载到我的页面.我想在页面中加载30个项目,然后当用户到达我希望它的网页底部然后加载另外30个项目.
到目前为止,我的网页上显示了30个项目,其中有一个下拉菜单可以过滤项目.我还有一个当用户到达页面底部时触发的函数.
谁能帮助我使用PHP脚本来完成这项工作并加载更多项目?我正在使用的代码如下.
谢谢
HTML
<section id="filters">
<select name="entries" onchange="filterEntries()">
<option value="*">show all</option>
<option value=".item323">323</option>
<option value=".item266">266</option>
<option value=".item277">277</option>
<option value=".item289">289</option>
</select>
</section> <!-- #filters -->
<div id="entries" class="clearfix">
<div class="ajaxloader"><img src="<?php bloginfo('template_url'); ?>/ajax_load.gif" alt="loading..." /></div><!--ajaxloader-->
</div><!--entries-->
<div class="ajaxloader"><img src="<?php bloginfo('template_url'); ?>/ajax_load.gif" alt="loading..." /></div><!--ajaxloader-->
Run Code Online (Sandbox Code Playgroud)
jQuery的
$(document).ready(function () {
loadData();
//Hide Loader for Infinite Scroll
$('div.ajaxloader').hide();
});
function loadData () {
//Show Loader for main content
$('#entries .ajaxloader').show();
//Pull in data from database
if (window.XMLHttpRequest) {// code for IE7+, Firefox, …Run Code Online (Sandbox Code Playgroud)