1.H5页面
1 <div class="btn" tapmode onclick="fnLogin();">登录</div>
2.AJAX代码
1 function fnLogin() { 2 var username = $api.byId('username'); 3 var password = $api.byId('password'); 4 var usernameValue = username.value; 5 var passwordValue = password.value; 6 7 api.ajax({ 8 url: 'http://d.apicloud.com/mcm/api/user/login', 9 method: 'post', 10 headers: { 11 "X-APICloud-AppId": "A6914327011091", 12 "X-APICloud-AppKey": "8ac17d22e49cb7982d82796097cec52a6c7cd01d.1475375422841" 13 }, 14 data: { 15 values: { 16 "username": usernameValue, 17 "password": passwordValue 18 } 19 } 20 }, function(ret, err) { 21 if (ret) { 22 //alert(JSON.stringify(ret)); 23 $api.setStorage('userInfo', ret); 24 api.alert({ 25 title: '提示', 26 msg: '登录成功', 27 }, function(ret, err) { 28 if (ret) { 29 api.closeToWin({ 30 name: 'main' 31 }); 32 } else { 33 alert(JSON.stringify(err)); 34 } 35 }); 36 } else { 37 alert(JSON.stringify(err)); 38 } 39 }); 40 }