头像上传(double ajax)
2024-11-23 18:55:34
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>首页</title> <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <link rel="stylesheet" href="{HOME_THEME_PATH}mobile/css/mui.min.css"> <link rel="stylesheet" href="{HOME_THEME_PATH}mobile/css/style1.css"> <script type="text/javascript" src="{HOME_THEME_PATH}js/jquery-1.9.1.min.js" ></script> <style> #fileid_auth_image7 { position: absolute; left: 0; width: 100%; height: 90px; top: 80px; opacity: 0 } </style> </head> <body> <header id="header" class="mui-bar bg-198cff" style="box-shadow: none"> <a href="/?s=member" class="mui-icon mui-icon-left-nav mui-pull-left f-c-fff"></a> <h1 class="mui-title f-c-fff">我的资料</h1> </header> <div style="margin-top: 44px;"></div> <label> <div> <img {if $member['avatar']} src="{dr_thumb($member['avatar'],75,75)}" {else} src="/statics/app/logo.png" {/if} id="dr_row_auth_image7" style="cursor:pointer;width:100px;height:100px;"> <input type="file" name="img7" id="fileid_auth_image7" accept="image/jpg,image/gif,image/png,image/jpeg"> <input type="hidden" class="cover7 i_check" name="data[avatar]" id="cover7" value="{$member['avatar']}" /> </div> </label> <p> {if $member['verify']==0} <img src="{HOME_THEME_PATH}mobile/images/web/mine-03.png"> {else if $member['verify']==1} <img src="{HOME_THEME_PATH}mobile/images/web/checking.png"> {else if $member['verify']==2} <img src="{HOME_THEME_PATH}mobile/images/web/reject.png"> {else if $member['verify']==9} <img src="{HOME_THEME_PATH}mobile/images/web/my-02.png"> {/if} <span> {if $member['identity']=="shipmaster"} 船主 {else} 货主 {/if} </span> </p> <ul> <li><a href="#"><span>用户名</span><span>{$member['username']}</span></a></li> <!--<li><a href="#"><span>所在地</span><span></span></a></li>--> <!--<li><a href="#"><span>性别</span><span></span></a></li>--> <li><a href="#"><span>手机号</span><span>{$member['phone']}</span></a></li> <!--<li><a href="#"><span>生日</span><span></span></a></li>--> <!--<li><a href="#"><span>QQ</span><span></span></a></li>--> <!--<li><a href="#"><span>邮箱</span><span></span></a></li>--> <li><a href="index.php?s=member&c=account&m=password"><span>密码</span><span>修改</span></a></li> </ul> <div> <button id="confirmBtn" type="button" class="mui-btn mui-btn-danger mui-btn-block">退出登录</button> </div> <script type="text/javascript" src="/statics/hmc/js/jquery.min.js"></script> <script src="{HOME_THEME_PATH}mobile/js/mui.min.js"></script> <script type="text/javascript" src="/statics/layer_mobile/layer.js"></script> <script type="text/javascript" src="{HOME_THEME_PATH}js/ajaxfileupload.js"></script> <!--<script type="text/javascript" src="{HOME_THEME_PATH}js/uploadpic.js"></script>--> <script> mui.init(); mui('body').on('tap','a',function(){document.location.href=this.href;}); document.getElementById("confirmBtn").addEventListener('tap', function() { var btnArray = ['否', '是']; mui.confirm('是否确认退出?', '', btnArray, function(e) { if (e.index == 1) { dr_loginout() } else { } }) }); function dr_loginout() { $.ajax({ type: "POST", dataType: "json", url: "/index.php?s=member&c=login&m=out", success: function(data) { mui.toast('退出成功'); var sync_url = data.syncurl; for (var i in sync_url) { $.ajax({ type: "GET", async: false, url: sync_url[i], dataType: "jsonp", success: function(json) {}, error: function() {} }) } setTimeout('window.location.href = "//www.ymc56.cn/"', 2000); }, error: function(HttpRequest, ajaxOptions, thrownError) { alert(HttpRequest.responseText); } }) } </script> <script> $(".ajax_file_upload7").live("change", function(){ console.log($(this)); layer.open({ type: 2, content: '上传中' }); var fileElementId = $(this).attr('id'); //input id var name = $(this).attr('name');//input name $.ajaxFileUpload({ url:'/index.php?s=member&c=api&m=ajax_upload&fname='+name, secureuri:false, fileElementId:fileElementId, dataType: 'json', success: function (data) { if(data.id){ $("#"+fileElementId).prev("img").attr('src', data.url); $("#"+fileElementId).next("input").val(data.id); $.get('/index.php?c=diy&m=avatar&id='+data.id); mui.toast('头像更新成功'); } else { mui.toast(data.msg); } layer.closeAll(); }, error: function (data, status, e){ layer.closeAll(); } }); }); </script> </body> </html>