...

View Full Version : new to ajax help me get this code working pls!!!



learner86
10-19-2007, 08:40 AM
Hi i've to combo boxes one for title ids and one for author ids... once i select title id author ids corresponding to tat title id should get loaded from the database.. i'm posting the whole code kindly help...

<script type="text/javascript">
function getEmployee()
{
xmlHttp=GetXmlHttpObject();
alert(xmlHttp);
var val=document.getElementById("projectName").value;
alert("i");

//xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="http://localhost:8080/timetracker2_original/Review_Timesheet1.jsp";
url=url+"?projname="+val;
url=url+"&sid="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=function()
{
var status;
var statusText;
try{ status = xmlHttp.status;}catch(e){document.write("Status Error "+status);}
try{ statusText = xmlHttp.statusText}catch(e){document.write("StatusText Error !!! "+statusText);}
//handle processed output
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
// store processed response text
var getVal = xmlHttp.responseText;
//document.getElementById("res").innerHTML=getVal;
}
}

xmlHttp.send(null);

alert(url);

}



function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
//document.write("XMLHttpRequest();");
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
//document.write("XMLHttpRequest2();");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
document.write("XMLHttpRequest3();");
}
}
return xmlHttp;
}




</script>


This code is inside the jsp page mentioned in the url varialbe i.e., Review_Timesheet1.jsp

A1ien51
10-19-2007, 10:27 PM
And you failed to say what your problem is.

Eric

rwedge
10-20-2007, 03:48 AM
This bit:
var status;
var statusText;
try{ status = xmlHttp.status;}catch(e){document.write("Status Error "+status);}
try{ statusText = xmlHttp.statusText}catch(e){document.write("StatusText Error !!! "+statusText);}is not good. Bad choices for variable names, will cause errors rather than check for them and, unless this script is ran as the page is rendered, document.write will open a new document.
The use of document.write in the GetXmlHttpObject() is not a good idea either. Alert it if you need to see what IE is doing.
IE7 does support native requests.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum