AJAX: permission denied error

This line of code causes Permission denied err when content has more than about 950 or 1000 characters.  If fewer characters then the line of code passes the request to savefile.asp which uses the file system object to save the results into a file on the server.

Question: is there an alternative to coding this way?

Escape was added  to take care of special characters in the text.

xmlHttp.open("post","savefile.asp?content=" + escape(content)  + "&medate=" + (new Date())); // .open(RequestType, Source);

Open in new window

Who is Participating?
hieloConnect With a Mentor Commented:
>>Question: is there an alternative to coding this way?
Well, for starters, you need to send a post request the right way. You are sending the data via the URL. That is a GET request. So the correct code for what you posted should really be:

xmlHttp.open("GET","savefile.asp?content=" + escape(content)  + "&medate=" + (new Date())); // .open(RequestType, Source);
Notice that it is GET (all upper case). 
Furthermore, simply changing "GET" to "POST" does NOT change the request type from GET to POST. Due to the size of the data you are sending, you may actually need a POST request, but like I said, simply changing GET to POST does not actually "convert" what you posted to a POST request. Instead you need to set the appropriate request headers and pass the values via the send() method, NOT via the url. Use the following:
var parameters = "content=" + encodeURIComponent(content)  + "&medate=" + (new Date());
xmlHttp.open('POST', "savefile.asp", true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", parameters.length);
xmlHttp.setRequestHeader("Connection", "close");

Open in new window

I just noticed that you use POST method but contains the parameters in the path
xmlHttp.open("post","savefile.asp?content=" + escape(content)  + "&medate=" + (new Date())); // .open(RequestType, Source);

if you use  post, the paramemters should be set in the send() method.

read this for more info
BTW if you want to check if the content is too long, you can do something like
if(content.length < 950)
     alert("Content is too long!");

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.