修改openid调用位置

This commit is contained in:
guange 2016-04-02 07:32:40 +08:00
parent 07c95ecacf
commit 5839959f0a
3 changed files with 53 additions and 52 deletions

View File

@ -219,58 +219,7 @@
<script src="/javascripts/jquery-1.3.2.js"></script>
<script src="/javascripts/baiduTemplate.js"></script>
<script src="/javascripts/wechat/wechat_dev.js"></script>
<script src="/javascripts/wechat/auth.js"></script>
<script type="text/javascript">
var bt=baidu.template;
bt.LEFT_DELIMITER='<!';
bt.RIGHT_DELIMITER='!>';
var apiUrl = '/api/v1/';
var loadDataFromServer = function(id, page){
//getOpenId(function(openid){
$.ajax({
url: apiUrl + 'activities/' + id +"?page=" + parseInt(page),
dataType: 'json',
success: function(data){
setTemplate(data.data, data.all_count, data.count, data.page);
},
error: function(xhr,status,err){
console.log(err);
}
});
//})
};
var setTemplate = function(data, all_count, count, page){
console.log(data);
var html=bt('t:result-list',{activities: data, all_count: all_count, count: count, page: page});
if (page == 0) {
$('#container').prepend(html);
} else {
$("#more_activities").remove();
$('#container').append(html);
}
descToggle();
};
//内容全部显示与部分隐藏
var descToggle = function(){
$(".post-all-content").each(function(){
var postHeight = $(this).height();
if (postHeight > 90){
$(this).parent().next().css("display","block");
$(this).parent().next().toggle(function(){
$(this).text("点击隐藏");
$(this).prev().css("height",postHeight);
},function(){
$(this).text("点击展开");
$(this).prev().css("height",90);
});
}
});
}
</script>
<script src="/javascripts/wechat/wechat_dev.js"></script>
</body>
</html>

View File

@ -15,16 +15,19 @@ $(function(){
}
window.getOpenId = function(cb){
alert(g_openid);
if (g_openid.length>0){
cb(g_openid);
}
var code = getUrlParam("code");
alert(code);
$.ajax({
url: '/wechat/get_open_id?code='+code,
type: 'get',
dataType: 'json',
success: function(data){
g_openid = data.openid;
alert(g_openid);
cb(g_openid);
},
error: function(xhr,err){

View File

@ -2,5 +2,54 @@
* Created by root on 3/25/16.
*/
$(document).ready(function(){
var bt=baidu.template;
bt.LEFT_DELIMITER='<!';
bt.RIGHT_DELIMITER='!>';
var apiUrl = '/api/v1/';
var loadDataFromServer = function(id, page){
getOpenId(function(openid){
$.ajax({
url: apiUrl + 'activities/' + openid +"?page=" + parseInt(page),
dataType: 'json',
success: function(data){
setTemplate(data.data, data.all_count, data.count, data.page);
},
error: function(xhr,status,err){
console.log(err);
}
});
})
};
var setTemplate = function(data, all_count, count, page){
console.log(data);
var html=bt('t:result-list',{activities: data, all_count: all_count, count: count, page: page});
if (page == 0) {
$('#container').prepend(html);
} else {
$("#more_activities").remove();
$('#container').append(html);
}
descToggle();
};
//内容全部显示与部分隐藏
var descToggle = function(){
$(".post-all-content").each(function(){
var postHeight = $(this).height();
if (postHeight > 90){
$(this).parent().next().css("display","block");
$(this).parent().next().toggle(function(){
$(this).text("点击隐藏");
$(this).prev().css("height",postHeight);
},function(){
$(this).text("点击展开");
$(this).prev().css("height",90);
});
}
});
}
loadDataFromServer(8686, 0);
});