mui下拉刷新的ajax实现
<script>
mui
.
init
({
swipeBack
:
false
,
pullRefresh
:
{
container
:
'#pullrefresh'
,
down
:
{
callback
:
pulldownRefresh
}
}
});
/**
* 下拉刷新具体业务实现
*/
var
last
=-
5
,
amount
=
5
;
function
pulldownRefresh
()
{
last
=
last
+
amount
;
var
table
=
document
.
body
.
querySelector
(
'.mui-table-view'
);
var
cells
=
document
.
body
.
querySelectorAll
(
'.mui-table-view-cell'
);
mui
.
ajax
({
type
:
"post"
,
dataType
:
"json"
,
url
:
"http://localhost/amazeui/?action=item"
,
data
:
"last="
+
last
+
"&amount="
+
amount
,
complete
:
function
(){
$
(
"#load"
).
hide
();},
success
:
function
(
msg
){
var
data
=
msg
;
var
tmp
=
''
;
$
.
each
(
data
,
function
(
i
,
n
){
var
li
=
document
.
createElement
(
'li'
);
li
.
className
=
'mui-table-view-cell'
;
li
.
innerHTML
=
'<a class="mui-navigate-right">'
+
n
.
itemname
+
'</a>'
;
//下拉刷新,新纪录插到最前面;
table
.
insertBefore
(
li
,
table
.
firstChild
);
});
}
});
mui
(
'#pullrefresh'
).
pullRefresh
().
endPulldownToRefresh
();
//refresh completed
}
if
(
mui
.
os
.
plus
)
{
mui
.
plusReady
(
function
()
{
setTimeout
(
function
()
{
mui
(
'#pullrefresh'
).
pullRefresh
().
pullupLoading
();
},
1000
);
});
}
else
{
mui
.
ready
(
function
()
{
mui
(
'#pullrefresh'
).
pullRefresh
().
pullupLoading
();
});
}
</script>