zenithwolf
08-27-2007, 10:17 PM
Hey,
I'm new to Ajax am trying to get ajax to get values from a jsp page when the html loads, but first time the page loads, it gives me an error saying "The data necessary to complete this operation is not yet available" for the xmlHTTPRequest.responseText but when i refresh the page, it loads perfectly! jsp tested and works so the problem resides in my ajax/html file.
EDIT: this reloading thing only works in IE, in mozilla this page doesnt work at all :(
heres my html (i dont know if I am doing this right though) any thoughts welcome and much appreciated:
<html>
<head>
<script type="text/javascript">
function ajaxFunction() {
var xmlHttp;
var optionID;
//generic code (www.w3schools.com)
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest(); }
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
//problem
var url="get.jsp?name=";
xmlHttp.open("GET", url,true);
xmlHttp.send(null);
var getVal = xmlHttp.responseText;
alert(getVal);
document.getElementById("myForm1").innerHTML=getVal;
}
</script>
</head>
<body onLoad="ajaxFunction()">
<table name="mytable" cellspacing="10">
<tr>
<td>
<form name="myForm" id="myForm1">
</form>
</td>
<td>
</td>
</tr>
</table>
</body>
</html>
I'm new to Ajax am trying to get ajax to get values from a jsp page when the html loads, but first time the page loads, it gives me an error saying "The data necessary to complete this operation is not yet available" for the xmlHTTPRequest.responseText but when i refresh the page, it loads perfectly! jsp tested and works so the problem resides in my ajax/html file.
EDIT: this reloading thing only works in IE, in mozilla this page doesnt work at all :(
heres my html (i dont know if I am doing this right though) any thoughts welcome and much appreciated:
<html>
<head>
<script type="text/javascript">
function ajaxFunction() {
var xmlHttp;
var optionID;
//generic code (www.w3schools.com)
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest(); }
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
//problem
var url="get.jsp?name=";
xmlHttp.open("GET", url,true);
xmlHttp.send(null);
var getVal = xmlHttp.responseText;
alert(getVal);
document.getElementById("myForm1").innerHTML=getVal;
}
</script>
</head>
<body onLoad="ajaxFunction()">
<table name="mytable" cellspacing="10">
<tr>
<td>
<form name="myForm" id="myForm1">
</form>
</td>
<td>
</td>
</tr>
</table>
</body>
</html>