1

I've a problem with javascript. I'm making a AJAX based upload and have an array of all files uploaded. If the site is reloaded I want to restore all files to the array.

I do like this:

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

And I get:

SecurityError: The operation is insecure.

I use the same origin, and on my local server: mylocal:88/init.php?page=upload

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

Gives me this error. Port, protocol and domain is the same.

Why and how to create a new file without getting this error?

1 Answers1

1

As far as I know Javascript runs on client machines, they cannot allow client to create files on the server otherwise hacking into servers would be very easy. The FILE object create file on the client side only.

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();

You can however try jquery:

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