...

View Full Version : Inserting data into textarea when page loads



raja_jan09
06-21-2010, 01:00 PM
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.

jmrker
06-21-2010, 10:51 PM
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!
:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum