1

Facebookアプリケーションでコード化されたクライアント側があり、後で使用するためにトークンをサーバーに保存したい

'token'という変数があり、次に'apple'という新しい関数を作成して、この変数をjson形式でtxtファイルに書き込みます。

$(document).ready(function(){

$("#submit").click(function(){

    //access token stuff
    var token = $("#link_input").val();
    //alert("Got Token: " + token + ". your application token");

    if (token.split('#access_token=')[1]) {
    var token = token.split('#access_token=')[1].split('&')[0];
    //alert(token);



function WriteToFile(apple)
    {
    $.post("save.php",{ 'token': apple },
        function(data){
            alert(data);
        }, "text"
    );
    return false;
    } 

私のphpファイル

<?php
$thefile = "new.json"; /* Our filename as defined earlier */
$towrite = $_POST["token"]; /* What we'll write to the file */
echo $towrite;
$openedfile = fopen($thefile, "w");
$encoded = json_encode($towrite);
fwrite($openedfile, $encoded);
fclose($openedfile);
return "<br> <br>".$towrite;

?>

しかし、私はそれを何も書くことができません

4

2 に答える 2

0

You must first create the file in the location and then set the right permissions or the PHP will not be able to write it.

于 2013-02-25T00:19:58.050 に答える
0

As it stands now, you define your WriteToFile function in JS, but you never call it. Change your JS to something like:

$(document).ready(function(){

    $("#submit").click(function(){

        //access token stuff
        var token = $("#link_input").val();
        //alert("Got Token: " + token + ". your application token");

        if (token.split('#access_token=')[1]) {
            var token = token.split('#access_token=')[1].split('&')[0];
            WriteToFile(token);
        }
    }



    function WriteToFile(apple) {
        $.post("save.php",{ 'token': apple },
            function(data){
                alert(data);
            }, "text");
        return false;
    }

};

Or:

$(document).ready(function(){

    $("#submit").click(function(){

        //access token stuff
        var token = $("#link_input").val();
        //alert("Got Token: " + token + ". your application token");

        if (token.split('#access_token=')[1]) {
            var token = token.split('#access_token=')[1].split('&')[0];
            $.post("save.php",{ 'token': token }, function(data){
                    alert(data);
                }, "text");
        }
    }

};
于 2013-02-25T00:58:10.773 に答える