diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index 1c14aece0..01dd135be 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -1,5 +1,5 @@ class WechatsController < ActionController::Base - layout 'wechat/layout' + layout 'base_wechat' wechat_responder @@ -179,9 +179,9 @@ class WechatsController < ActionController::Base uw = UserWechat.find_by_id(params[:state]) uw.user_id = user.id uw.save! - render :text => {status:0, msg: "绑定成功"} + render :text => {status:0, msg: "绑定成功"}.to_json rescue Exception=>e - render :text => {status: -1, msg: e.message} + render :text => {status: -1, msg: e.message}.to_json end end diff --git a/app/views/wechats/layout.html.erb b/app/views/layouts/base_wechat.html.erb similarity index 96% rename from app/views/wechats/layout.html.erb rename to app/views/layouts/base_wechat.html.erb index 8f93ac9a1..729f762ac 100644 --- a/app/views/wechats/layout.html.erb +++ b/app/views/layouts/base_wechat.html.erb @@ -7,6 +7,7 @@ 绑定用户 + <%= yield %> diff --git a/app/views/wechats/login.html.erb b/app/views/wechats/login.html.erb index d0cecb5f9..3d8037c7c 100644 --- a/app/views/wechats/login.html.erb +++ b/app/views/wechats/login.html.erb @@ -50,9 +50,17 @@ type: "POST", url: $("#main_login_form").attr("action"), data:data, - dataType: "json" - }).done(function(data){ - + dataType: 'json', + success: function(data){ + console.log(data); + if(data.status == 0){ + byConfirm(data.msg, function(){ + window.closeWindow(); + }); + } else { + byAlert(data.msg, "绑定失败"); + } + } }); }) diff --git a/public/javascripts/wechat/alert.js b/public/javascripts/wechat/alert.js index bda0150a9..e41718fc2 100644 --- a/public/javascripts/wechat/alert.js +++ b/public/javascripts/wechat/alert.js @@ -35,4 +35,9 @@ $(function(){ $dialog.hide(); }); } + + + window.closeWindow = function(){ + WeixinJSBridge.call('closeWindow'); + } }); \ No newline at end of file