[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


AJAX:  permission denied error

Posted on 2008-11-12
Medium Priority
Last Modified: 2012-05-05
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

Question by:KeithMcElroy
  • 2
LVL 15

Expert Comment

ID: 22947262
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
LVL 15

Expert Comment

ID: 22947271
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

LVL 82

Accepted Solution

hielo earned 2000 total points
ID: 22947399
>>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


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello World !, Thanks : My Sincere thanks to @Michael Male who encouraged me to write an article on this in my  blog (http://scribblejava.wordpress.com). Introduction:       There are several technical issues a developer may face in his…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question