AJAX:  permission denied error

Posted on 2008-11-12
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."post","savefile.asp?content=" + escape(content)  + "&medate=" + (new Date())); // .open(RequestType, Source);

Open in new window

Question by:KeithMcElroy
    LVL 15

    Expert Comment

    I just noticed that you use POST method but contains the parameters in the path"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

    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

    >>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:"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());'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

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
    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 …
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    731 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now