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

KeithMcElroyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

quincydudeCommented:
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
http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
0
quincydudeCommented:
BTW if you want to check if the content is too long, you can do something like
if(content.length < 950)
{
     xmlHttp.open(...);
}
else
     alert("Content is too long!");

Open in new window

0
hieloCommented:
>>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");
xmlHttp.send(parameters);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AJAX

From novice to tech pro — start learning today.