Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Inserting data into textarea when page loads

    Hi All,

    I am new to javascript and actually I need to insert the data into a textarea from a text file when the user loads the browser..

    and I am using this program to do it..but its throwing error 405, I dont know whats the problem..can any one please check the code or give me some code to do the same funtionality.

    <script type="text/javascript">
    function getfile()
    {
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null)
    {
    alert("Browser does not support HTTP Request");
    return;
    }
    var url = "${pageContext.request.contextPath}/static/files/email1.txt";
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("POST", url, true);
    xmlHttp.send(null);
    }

    function stateChanged()
    {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
    {
    var emm = xmlHttp.responseText;
    alert(emm);
    }
    }
    function GetXmlHttpObject()
    {
    var xmlHttp = null;
    try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
    }
    catch (e)
    {
    //Internet Explorer
    try
    {
    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    }
    return xmlHttp;
    }
    </script>

    can one give me some idea regarding this.


    Thanks in Advance,

    Best Regards,
    Rajasekhar.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,091
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb Something to consider ...

    It has been my experience that if I try to load a text file with ajax
    during the initialization of the program, I always get errors.
    I appears to me that the load happens before the page has finished loading.

    My solution was to set-up the page as normal, but put a button
    that lets the user load the information using the ajax routines
    AFTER the page has been displayed. I have been successful with this technique.

    Good Luck!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •