我有一个Facebook应用程序编码的客户端,我想令牌存储在我的服务器,供以后使用写一个AJAX变量txt文件
有一个叫“令牌”变量,然后创建一个新的功能所谓的“苹果”在一个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;
?>
,但我不能把它写什么
1 /文件模式? 2/try:'fopen($ thefile,“w +”)'3/error_log? – Julien 2013-02-25 00:16:43
呃...你永远不会在你的javascript中调用你的'WriteToFile'函数。 – Jon 2013-02-25 00:25:09
检查你的'fopen'调用返回的值。如果打开文件失败,它将返回'false'而不是文件句柄。 – user18477575 2013-02-25 00:45:13