新文件() - 操作不安全

时间:2013-04-29 09:19:47

标签: javascript

我的javascript问题。我正在进行基于AJAX的上传,并且已经上传了所有文件的数组。如果重新加载该站点,我想将所有文件还原到该阵列。

我喜欢这个:

var file = new File({the url to the file on my server});

我得到了:

SecurityError: The operation is insecure.

我使用相同的来源,并在我的本地服务器上:mylocal:88 / init.php?page = upload

var file = new File('http://mylocal:88/init.php?file=12345');

给我这个错误。端口,协议和域名是相同的。

为什么以及如何在不收到此错误的情况下创建新文件?

1 个答案:

答案 0 :(得分:1)

据我所知,Javascript在客户端计算机上运行,​​它们不允许客户端在服务器上创建文件,否则很容易入侵服务器。 FILE对象仅在客户端创建文件。

EG: var file = new File("myfile.txt");

file.open("write,create", "text");
file.writeln("The quick brown fox jumped over the lazy dogs");
file.close();

但你可以尝试jquery:

$.get('/init.php?file=12345', function(data) {//This function run when the request is completed.
      alert(data);
      console.log(data);
});