ajax请求:
一、从服务器端请求数据:
var url = '';
url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='+ appid +'&secret='+ secret +'&code='+ code +'&grant_type=authorization_code';
$.ajax({ type: 'GET', url: url, dataType: 'json', success: function(data){ alert(JSON.stringify(data)) }, error: function(xhr, type){ alert('Ajax error!') } });
二、发送数据到服务器
// 参与活动 function joinActivity(msg){ $.ajax({ type: 'GET', url: 'http://ebsig.mcake.com/ajax-shop/activity/wsj.ajax', data: { operFlg: 'join', gid: gid, oid:oid, msg: msg}, dataType: 'json', success: function(data){ if(data.code == 200) { $('#js_step9').show(); } else { // 已经参加过 alert(data.message); } }, error: function(xhr, type){ alert('Ajax error!') } }); }
函数调用:
joinActivity(val);
整体页面js部署:
//初始化设置
var gid = '', oid = getOid(); $step1 = $('#js_step1'), $step2 = $('#js_step2'), $step3 = $('#js_step3'), $step4 = $('#js_step4'), $step5 = $('#js_step5'), $step6 = $('#js_step6'), $step7 = $('#js_step7'), $step8 = $('#js_step8'), $step9 = $('#js_step9'), $step10 = $('#js_step10'), $step11 = $('#js_step11'), $step12 = $('#js_step12'), $step13 = $('#js_step13'), menTimeer = null; $(function(){ // 初始化weixin 配置 (function initConfig(){ execJs(); })();
// 授权
function auth(appId){
} }); function execJs() { function imgShow(ele){ var i=-1; var len=ele.children("img").length; function imgAnimate(){ //设置走光动画 i++; if(i<len){ setTimeout(function(){ ele.children("img").eq(i).show().siblings().hide(); imgAnimate(); //内部回调 },300); } } imgAnimate(); //执行一次动画,否则其他动画不隐藏 } } imgShow($("#js_loading"));//立刻执行一次 var timeer = setInterval(function(){imgShow($("#js_loading"))},1200);/*循环执行*/ //loading动画 function imgLoad(ele){} function step1(){
$step1.hide();
$step3.show();
} function step2(){} function step3(){} var animation = { menAnimation: function(){}, cdAnimation: function(){}, zdAnimation: function(){}, sdAnimation: function(){}, }
// 发起活动
function initActivity(callback){}
// 查看活动
function checkActivity(gid){}
// 参与活动
function joinActivity(msg){}
//分享
function shareWx(url){}
(function bindEvent () {
// 步骤
$step1.on('click', function(){
clearInterval(menTimeer);
step2();
});
$step2.on('click', function(){
$("#js_share").find('img').hide();
location.href = location.origin + location.pathname + '?gid=' + gid;
step2();
$step1.hide();
});
})(); }
var $bao = $('#js_bao'), $step2 = $('#js_step2'), $step3 = $('#js_step3'); (function initConfig(){ execJs(); })(); function execJs() { function step1(){ $bao.find("li").click(function(){ $(this).addClass("on").siblings().removeClass("on"); }) } (function bindEvent () { step1(); })(); }