绑定提交改为ajax

chenlw_dev
guange 10 years ago
parent a59f65a455
commit 509d4a3df7

@ -1,5 +1,5 @@
class WechatsController < ActionController::Base class WechatsController < ActionController::Base
layout 'wechat/layout' layout 'base_wechat'
wechat_responder wechat_responder
@ -179,9 +179,9 @@ class WechatsController < ActionController::Base
uw = UserWechat.find_by_id(params[:state]) uw = UserWechat.find_by_id(params[:state])
uw.user_id = user.id uw.user_id = user.id
uw.save! uw.save!
render :text => {status:0, msg: "绑定成功"} render :text => {status:0, msg: "绑定成功"}.to_json
rescue Exception=>e rescue Exception=>e
render :text => {status: -1, msg: e.message} render :text => {status: -1, msg: e.message}.to_json
end end
end end

@ -7,6 +7,7 @@
<title>绑定用户</title> <title>绑定用户</title>
<link rel="stylesheet" href="/stylesheets/weui/weui.min.css"/> <link rel="stylesheet" href="/stylesheets/weui/weui.min.css"/>
<script src="/javascripts/jquery.min.js"></script> <script src="/javascripts/jquery.min.js"></script>
<script src="/javascripts/wechat/alert.js"></script>
</head> </head>
<%= yield %> <%= yield %>

@ -50,9 +50,17 @@
type: "POST", type: "POST",
url: $("#main_login_form").attr("action"), url: $("#main_login_form").attr("action"),
data:data, data:data,
dataType: "json" dataType: 'json',
}).done(function(data){ success: function(data){
console.log(data);
if(data.status == 0){
byConfirm(data.msg, function(){
window.closeWindow();
});
} else {
byAlert(data.msg, "绑定失败");
}
}
}); });
}) })

@ -35,4 +35,9 @@ $(function(){
$dialog.hide(); $dialog.hide();
}); });
} }
window.closeWindow = function(){
WeixinJSBridge.call('closeWindow');
}
}); });
Loading…
Cancel
Save