写一个ajax变量txt文件 [英] Writing an ajax variable to txt file
本文介绍了写一个ajax变量txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Facebook应用程序codeD的客户端,我想保存标记我的服务器,供以后使用
I have a facebook application coded client side and I want to store the tokens on my server for later use
有一个名为变量'令牌'然后我创建了一个名为苹果的新功能,来写这个变量的JSON格式到一个txt文件
There is a variable called 'token' and I then create a new function called 'apple' to write this variable in a json format to a txt file
$(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文件
My php file
<?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;
?>
但我不能把它写什么
but i cant get it to write anything
推荐答案
目前的情况是,您可以定义JS你的将writeToFile
的功能,但你的从不的调用它。
改变你的JS来是这样的:
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;
}
};
或者
$(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");
}
}
};
这篇关于写一个ajax变量txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文