我有一個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