php,如何调用javascript函数?
我正在尝试使用 gigya auth 属性来登录我网站上的用户。他们有一个函数,需要在我验证凭据后调用,如 说明
我有一个表单,当我提交表单时,我将其发送到login.php,在那里我对我的用户进行身份验证。我的问题是如何调用socialize.notifyLogin
?
这是javascript:
<script type="text/javascript"> var conf = { APIKey:'2_9E9r_ojXEqzZJqKk7mRqvs81LtiSvUmBcm' }; </script>
<script type="text/javascript">
var secret = 'eIqtclW2CxC6qvmT55MvOxZ5Rm7V5JhBV/gioJLKIxM=';
var yourSiteUid= '<?php echo $talentnum;?>'; // siteUID should be retrieved from your user management system
function your_b64_hmac_sha1(secret, datePlusSite) {
var b64Sig = ''; // Place your implementation here ...
return b64Sig;
}
function printResponse(response) {
if ( response.errorCode == 0 ) {
alert('After notifyLogin');
}
}
var dateStr = getCurrentTime();
var datePlusSite = dateStr + "_" + yourSiteUid;
var yourSig = your_b64_hmac_sha1(secret, datePlusSite);
var params={
siteUID:yourSiteUid,
timestamp:dateStr,
signature:yourSig,
callback:printResponse
};
gigya.services.socialize.notifyLogin(conf,params);
</script>
为了更清楚,我在login.php 中设置了$talentnum;
。所以我有表单
,我将其发送到login.php
和一个重定向页面
...其中调用socialize。会是notifyLogin吗?
谢谢, 任何想法都有帮助
i am trying to use gigya auth properties to login users on my website. They have a function that needs to be called after i authenticate the credentials as seen in this illustration
I have a form and when i submit the form i send it to login.php where i authenticate my users. My question is how do i call socialize.notifyLogin
?.
this is the javascript:
<script type="text/javascript"> var conf = { APIKey:'2_9E9r_ojXEqzZJqKk7mRqvs81LtiSvUmBcm' }; </script>
<script type="text/javascript">
var secret = 'eIqtclW2CxC6qvmT55MvOxZ5Rm7V5JhBV/gioJLKIxM=';
var yourSiteUid= '<?php echo $talentnum;?>'; // siteUID should be retrieved from your user management system
function your_b64_hmac_sha1(secret, datePlusSite) {
var b64Sig = ''; // Place your implementation here ...
return b64Sig;
}
function printResponse(response) {
if ( response.errorCode == 0 ) {
alert('After notifyLogin');
}
}
var dateStr = getCurrentTime();
var datePlusSite = dateStr + "_" + yourSiteUid;
var yourSig = your_b64_hmac_sha1(secret, datePlusSite);
var params={
siteUID:yourSiteUid,
timestamp:dateStr,
signature:yourSig,
callback:printResponse
};
gigya.services.socialize.notifyLogin(conf,params);
</script>
to be more clear i set the $talentnum;
inside my login.php. so i have the form
i send it ti the login.php
and a redirect page
... Where the call to socialize.notifyLogin
will be?
thanks,
any idea helps
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有两个选择:
如果您调用 login.php 作为 HTML 表单的目标,则应在成功登录后将用户重定向到新的 HTML 页面。这个新的 HTML 页面应包含
socialize.notifyLogin
调用。如果您通过 AJAX 请求调用 login.php,则应在 AJAX 请求的“成功”回调中调用
socialize.notifyLogin
。但是,在任何情况下,您都无法直接从 PHP 脚本执行 Javascript 函数。 PHP 在 Javascript 作为 HTML 文档的输出发送给用户之前在服务器上执行,因此无法直接执行 Javascript 函数。
You have two options:
If you call login.php as the target of an HTML form, you should redirect the user to a new HTML page upon successful login. This new HTML page should contain the
socialize.notifyLogin
call.If you call login.php via an AJAX request, you should call
socialize.notifyLogin
in the "success" callback of the AJAX request.In no case, however, will you be able to execute the Javascript function directly from your PHP script. PHP executes on the server before the Javascript is sent to the user as output with your HTML document, and therefore cannot execute Javascript functions directly.
PHP 在页面加载之前执行,因此您无法从 PHP 调用 JavaScript 函数。
PHP is executed before the page loads, therefore you cannot call a JavaScript function from PHP.