Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ajax issue

Status
Not open for further replies.

bbvic

Technical User
Oct 21, 2004
51
US
I have two problems.
one is my ajax code does not work.
the other is I have an error in here.

document.getElementById("medicalid").innerHTML=xmlDoc.getElementsByTagName("hospital")[0].childNodes[0].nodeValue;
error says the value is null.

Would you please help how i can get the node value?


[ file name: medical.xsl ]

<script>
var xmlHttp

function showCustomer(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}

var url='../stat/medical.html?patient_id=<xsl:value-of select="pid" />&amp;medicalid='+str;

xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
var xmlDoc=xmlHttp.responseXML.documentElement;
document.getElementById("medicalid").innerHTML=xmlDoc.getElementsByTagName("doctors")[0].childNodes[0].nodeValue;

}
}

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>
<table>
<tr>
<td>
<select id="medicalid" name="medicalid" onchange="return stateChanged()">
<xsl:for-each select="/document/stat/medical/hospital/medical">
<option value="{./@medical_field_id}"><xsl:value-of select="./@medical_field_name" /></option>
</xsl:for-each>
</select>
</td>
</tr>
<tr>
<td>
<select id="medicalfield" name="medicalfield" >
<xsl:for-each select="/document/stat/medical/doctors/doctor">
<option value="{./@doctorid}"><xsl:value-of select="./@doctor_name" /></option>
</xsl:for-each>
</select>
</td>
</tr>
</table>

[ file name: ../test/medical.xml ]

<document>
<testarea>
<stat>
<xsp:logic>

String medicalid=<xsp-request:get-parameter name="medicalid"/>';

</xsp:logic>

<medical>
<hospital>
<medical medical_field_id="PS" medical_field_name="Plastic Surgeory"></medical>
<medical medical_field_id="IM" medical_field_name="Internal Medicine"></medical>
<medical medical_field_id="OP" medical_field_name="Orthepedics"></medical>
</hospital>

<!-- if medicalid is null, it displays nothing, if medicalid is not null, it gets medicalid (get-parameter). -->
<doctors>
<doctor doctorid="MDPS" doctor_name="Test_2 M.D"></medical>
<doctor doctorid="MDPS" doctor_name="Test_1 M.D"></medical>
<doctor doctorid="MDPS" doctor_name="Test_3 M.D"></medical>
</doctors>
<medical>
<stat>
<testarea>
<document>


 
Instead of this:

Code:
xmlDoc.getElementsByTagName("doctors")[0].childNodes[0].nodeValue;

try this:

Code:
xmlDoc.getElementsByTagName("doctors")[0].getElementsByTagName("doctor")[0].nodeValue;

It might be that whitespace is acting as a childnode.

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
i tried your code..it still gets null return value.
 
i tried alert(xmlDoc) and it gets null ..
 
Also you've not specified a type for your script element. Perhaps validating your page would be a good start? You've so many things wrong, debugging this would take forever.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Ignore the bit about duplicate IDs - my eyes were playing tricks on me. I still think validating your source would eb a good way to go.

I'd also use a fully-qualified URL for your AJAX source, not a relative path. Give that a whirl.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
unfortunately, you cannot access to the dev site.
there is a limited access. only company computer can access now..
sorry...
 
I suggested that YOU validate your code - I didn't ask for a URL.

And if the code you posted is EVERYTHING, where are things like the open and close HTML and BODY tags? Is that REALLY everything? if so, you need to seriously give some structure to your document.

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top