我在这里和其他地方进行了宗教搜索,以解决我的问题无济于事。我发现了许多代码片段,其中包含从javascript到jquery的样本,声称能够创建和写入txt或html文件,但它们都没有为我工作。这是我的问题......
我有一个非常轻的php(或html)页面,它使用javascript API录制视频,将其上传到云端的服务器,并为我提供一个令牌,通过该令牌我可以访问该视频进行播放。它非常适合这一点。
我尝试做的是捕获包含令牌的javascript变量,然后创建一个新的html(或php)文件,其中包含使用该令牌显示视频的非常简单的代码。
这是代码的本质......
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//assets.ziggeo.com/css/ziggeo-betajs-player.min.css" />
<script src="//assets.ziggeo.com/js/ziggeo-jquery-json2-betajs-player.min.js">
</script>
<script>
ZiggeoApi.token = "883afacbe59949feae1c9c661d653257";
ZiggeoApi.Events.on("submitted", function (data) {
var token = '<ziggeo ziggeo-video=' + data.video.token + '>';
document.getElementById("output").innerHTML=token;
});
</script>
</head>
<body>
<!-- next line displays the recorder -->
<ziggeo></ziggeo>
<p></p>
<font color=black>
<!-- next line displays the recorded video using the generated token for id -->
<p id='output'></p>
</font>
</body>
</html>
...在上面,在创建视频后,ZiggeoApi.Events.on(&#34;提交&#34; ...行返回data.video.token中的令牌。然后我试图做而不是在&#34; id&#34;标识的元素中显示同一页面上的视频,输出头部分中的代码加上新html文件的正文部分中的代码... &#39;&#39; ...但是每次javascript努力都失败了。没有错误,没有投诉,也没有文件。
我尝试将javascript变量data.video.token转换为php变量,因为我知道我可以让php写入该文件。我有这方面的工作代码,除了将javascript var转换为php var还没有工作。
任何帮助表示感谢。
以下是我尝试将文件写入的一些代码示例...
<script>
var txtFile = "test.html";
var file = new File(txtFile);
var str = '<ziggeo ziggeo-video=' + data.video.token + '>';
file.open("w"); // open file with write access
file.write(str);
file.close();
</script>
......上面没有工作......
<script>
import System.IO;
import System; // Used for getting the date
function Start () {
// Create an instance of StreamWriter to write text to a file.
sw = new StreamWriter("/home4/htlwoadm/public_html/ziggeo/test.txt");
// Add some text to the file.
sw.Write("This is the ");
sw.WriteLine("header for the file.");
sw.WriteLine("-------------------");
// Arbitrary objects can also be written to the file.
sw.Write("The date is: ");
sw.WriteLine(DateTime.Now);
sw.Close();
}
</script>
...上面根本没有工作......所以没有尝试修改它......
<html><head></head>
<body>
<script>
WriteFile();
</script>
<script>
function WriteFile()
{
var fh = fopen("test.html", 3); // Open the file for writing
if(fh!=-1) // If the file has been successfully opened {
var str = "Some text goes here...";
fwrite(fh, str); // Write the string to a file
fclose(fh); // Close the file
}
}
</script>
</body></html>
...上面也没有工作所以也没有修改它......
<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
...上面有效,但似乎无法将上面的javascript变量(data.video.token)转换为php,因此无法修改它。
任何帮助表示感谢。
答案 0 :(得分:0)
通常通过某种HTTP POST调用将浏览器中的值提交到服务器。您可以通过AJAX(请参阅此处:jQuery send string as POST parameters)或通过“传统”html表单(请参阅此处:How to add additional fields to form before submit?)来执行此操作。