1

我有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');

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

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

4

1 回答 1

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);
});
于 2013-04-29T09:29:53.970 回答