我是 code-igniter 的新手。在我看来,我添加了这段代码以在我的网站中启用谷歌登录。
<html lang="en">
<head>
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="720765566138-5c6jreo4r7ma6cm0hdblj5cmjtdiruk4.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer> </script>
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn" data-onfailure="onFailure" data-theme="dark"></div>
<script>
function onFailure(msg){ console.log(msg); }
function onSignIn(googleUser) {
console.log("onSignIn");
var profile = googleUser.getBasicProfile();
var user_name = profile.getName();
var id = googleUser.getAuthResponse().id;
};
</script>
</body>
</html>
如何将变量 user_name 和 id 发送到 Controller ,以便调用模型将值插入数据库。
最佳答案
获取信息后,您可以简单地使用 ajax 发布信息(使用下面的 jquery):
<script>
function onSignIn(googleUser)
{
var profile = googleUser.getBasicProfile();
var user_name = profile.getName();
var id = googleUser.getAuthResponse().id;
$.ajax({
'url': 'the/path/to/controller',
'type': 'POST',
'data':{'user_name': user_name, 'id':id},
'success': function(){}, //up to you
'error': function() // up to you
})
};
</script>
关于javascript - 如何在 codeigniter 中将数据从 View 发送到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35917074/