开发者

javascript call php in backend

开发者 https://www.devze.com 2023-03-02 04:41 出处:网络
I have a facebook login button in my index.php page. <f开发者_高级运维b:login-button onlogin=\"OnLogIn()\"></fb:login-button>

I have a facebook login button in my index.php page.

<f开发者_高级运维b:login-button onlogin="OnLogIn()"></fb:login-button>

when user click on the button, it calls a function OnLogIn() in javascript.

<script type="text/javascript">
    function OnLogIn() {
        if(FB.getSession()!=null){
            //pass some value to save.php
        }
    }
</script>

What should i do to let the OnLogIn() call save.php page to store some data in the database?


You will need to use some form of AJAX to make a call to the server from JavaScript. See the jQuery AJAX libraries. However, you will want to make sure this call is secured, i.e., cannot be made manually by malicious users who want to add data to your database.


The answer you need is AJAX. I recommend spending some time learning how it works here.

AJAX will allow you to call a remote page on the server and get responses from it. That remote page can do anything that any normal php script could do, including as you need, save info to the database.


This is a skeleton for you:

<script type="text/javascript">
    function OnLogIn() {
        if(FB.getSession()!=null){
            $.ajax({
                url: 'save.php'
                data: { }
            }).success(function(data, status, xhr) {

            });
        }
    }
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消