"No Properties" error... can't navigate dom elements. Please help...

P

pbd22

hi.

for some reason i am not able to navigate the dom.
i keep getting the 'no properties' error but i think i
am doing everything right. this is an XML response
from an AJAX call.

The ajax method to call the server code looks like this.
i am passing a cookie as a parameter:

Code:

var stockquote = get_cookie("stockquote");
ajaxSend('GET','data.aspx',stockquote, dataResponseHandler, false);



the code coming from the server looks like this:

Code:

Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

Dim con As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection(connection stuff...)
Dim editcriteriacmd As System.Data.SqlClient.SqlCommand = New
Data.SqlClient.SqlCommand(select statement stuff..., con)

con.Open()

'EDITPROFILE STUFF

Dim edit_dr As Data.SqlClient.SqlDataReader =
editcriteriacmd.ExecuteReader(Data.CommandBehavior.CloseConnection)

'main declarations
dim sex as string
dim age_frm as string
dim age_to as string
dim type as string
[SNIP]

If edit_dr.HasRows Then
While edit_dr.Read
sex = edit_dr.Item("sex").ToString()
age_frm = edit_dr.Item("age1").ToString()
age_to = edit_dr.Item("age2").ToString()
type = edit_dr.Item("type").ToString()
[SNIP]
End While
End If

edit_dr.Close()

Dim sbhtml As New System.Text.StringBuilder

sbhtml.Append("<?xml version='1.0' encoding='ISO-8859-1'?>")
sbhtml.Append("<search>")
sbhtml.Append("<sex>")
sbhtml.Append(sex.ToString)
sbhtml.Append("</sex>")
sbhtml.Append("<agefrom>")
sbhtml.Append(age_frm.ToString)
sbhtml.Append("</agefrom>")
sbhtml.Append("<ageto>")
sbhtml.Append(age_to.ToString)
sbhtml.Append("</ageto>")
sbhtml.Append("<type>")
sbhtml.Append(type.ToString)
sbhtml.Append("</type>")
[SNIP]
sbhtml.Append("</search>")

Context.Response.ContentType = "text/xml"
Response.Write(sbhtml.ToString)

End Sub



the response is parsed in the dataResponseHandler function.

Code:

function dataResponseHandler(ajaxRequest)

{ //1

// if xmlhttp shows "loaded"
if (ajaxRequest.readyState==4)

{ //2

// if "OK"
if
(ajaxRequest.status==200)

{ //3

try { //4

//UNCOMMENT FOR
ERROR CHECKING - RESPONSETEXT IN NEW WINDOW
//var doc =
ajaxRequest.responseText;
//
doc=doc.replace(/</g, '<').replace(/\>/g, '>');

//childWin=window.open("", "childwin");

//childWin.document.write("<pre>"+doc+"</pre>");

//childWin.document.close();

var dom =
parse(ajaxRequest.responseText);

var search =
dom.getElementsByTagName('search').item(0);



if (search) {
alert("search has something") } else { alert("search is empty"); }

var sex;
var age_frm;
var age_to;
var type;
[SNIP]

if
(search.getElementsByTagName("sex")[0].nodeValue != "") {
sex =
search.getElementsByTagName("sex")[0].nodeValue;
alert("sex:
"+sex);
}

if
(search.getElementsByTagName("age_frm")[0].firstChild.nodeValue != "")
{
age_frm =
search.getElementsByTagName("age_frm")[0].firstChild.nodeValue;

alert("agef: "+age_frm);
}

if
(search.getElementsByTagName("age_to")[0].firstChild.nodeValue != "") {
age_to =
search.getElementsByTagName("age_to")[0].firstChild.nodeValue;

alert("aget: "+age_to);
}

if
(search.getElementsByTagName("type")[0].firstChild.nodeValue != "") {
type =
search.getElementsByTagName("type")[0].firstChild.nodeValue;

alert("type: "+type);
}

} //4

catch (e) { //5

alert("There has
been an error. The problem is that " + e.message + ". This is a '" +
e.name + "' problem.");

} //5

} //3

else

{ //6
alert("Problem retrieving
XML data")
} //6

} //2

} //1




i am parsing the code using the below parse function:

Code:

function parse(xml) {

var dom;

try {
dom = new
ActiveXObject("Microsoft.XMLDOM");
dom.async = false;
dom.loadXML(xml);
} catch (error) {
try {
var parser = new
DOMParser();
dom =
parser.parseFromString(xml, "text/xml");
delete parser;
} catch (error2) {
if (debug)
alert("XML parsing is
not supported.");
}
}

return dom;

}



no matter what i do i keep getting that search has no properties. but
the below line is correct, isn't it?
var search = dom.getElementsByTagName('search').item(0);

so, if that is correct, then the problem is the content of the
response. but, when i uncomment my errorhandling code:

//UNCOMMENT FOR ERROR CHECKING - RESPONSETEXT IN NEW WINDOW
//var doc = ajaxRequest.responseText;
// doc=doc.replace(/</g, '<').replace(/\>/g, '>');
//childWin=window.open("", "childwin");
//childWin.document.write("<pre>"+doc+"</pre>");
//childWin.document.close();

i get the below line:

<?xml version='1.0'
encoding='ISO-8859-1'?><search><sex>male</sex><agefrom>18</agefrom><ageto>100</ageto><type>sometype</type></search>


so, that is everything. i am probably overlooking something obvious
but, at this point, i need another set of eyes to point
it out.

thanks.
 
P

pbd22

ok.

i have sorted this out.
i had a spelling error in the XML doc.
hi.

for some reason i am not able to navigate the dom.
i keep getting the 'no properties' error but i think i
am doing everything right. this is an XML response
from an AJAX call.

The ajax method to call the server code looks like this.
i am passing a cookie as a parameter:

Code:

var stockquote = get_cookie("stockquote");
ajaxSend('GET','data.aspx',stockquote, dataResponseHandler, false);



the code coming from the server looks like this:

Code:

Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

Dim con As System.Data.SqlClient.SqlConnection = New
System.Data.SqlClient.SqlConnection(connection stuff...)
Dim editcriteriacmd As System.Data.SqlClient.SqlCommand = New
Data.SqlClient.SqlCommand(select statement stuff..., con)

con.Open()

'EDITPROFILE STUFF

Dim edit_dr As Data.SqlClient.SqlDataReader =
editcriteriacmd.ExecuteReader(Data.CommandBehavior.CloseConnection)

'main declarations
dim sex as string
dim age_frm as string
dim age_to as string
dim type as string
[SNIP]

If edit_dr.HasRows Then
While edit_dr.Read
sex = edit_dr.Item("sex").ToString()
age_frm = edit_dr.Item("age1").ToString()
age_to = edit_dr.Item("age2").ToString()
type = edit_dr.Item("type").ToString()
[SNIP]
End While
End If

edit_dr.Close()

Dim sbhtml As New System.Text.StringBuilder

sbhtml.Append("<?xml version='1.0' encoding='ISO-8859-1'?>")
sbhtml.Append("<search>")
sbhtml.Append("<sex>")
sbhtml.Append(sex.ToString)
sbhtml.Append("</sex>")
sbhtml.Append("<agefrom>")
sbhtml.Append(age_frm.ToString)
sbhtml.Append("</agefrom>")
sbhtml.Append("<ageto>")
sbhtml.Append(age_to.ToString)
sbhtml.Append("</ageto>")
sbhtml.Append("<type>")
sbhtml.Append(type.ToString)
sbhtml.Append("</type>")
[SNIP]
sbhtml.Append("</search>")

Context.Response.ContentType = "text/xml"
Response.Write(sbhtml.ToString)

End Sub



the response is parsed in the dataResponseHandler function.

Code:

function dataResponseHandler(ajaxRequest)

{ //1

// if xmlhttp shows "loaded"
if (ajaxRequest.readyState==4)

{ //2

// if "OK"
if
(ajaxRequest.status==200)

{ //3

try { //4

//UNCOMMENT FOR
ERROR CHECKING - RESPONSETEXT IN NEW WINDOW
//var doc =
ajaxRequest.responseText;
//
doc=doc.replace(/</g, '<').replace(/\>/g, '>');

//childWin=window.open("", "childwin");

//childWin.document.write("<pre>"+doc+"</pre>");

//childWin.document.close();

var dom =
parse(ajaxRequest.responseText);

var search =
dom.getElementsByTagName('search').item(0);



if (search) {
alert("search has something") } else { alert("search is empty"); }

var sex;
var age_frm;
var age_to;
var type;
[SNIP]

if
(search.getElementsByTagName("sex")[0].nodeValue != "") {
sex =
search.getElementsByTagName("sex")[0].nodeValue;
alert("sex:
"+sex);
}

if
(search.getElementsByTagName("age_frm")[0].firstChild.nodeValue != "")
{
age_frm =
search.getElementsByTagName("age_frm")[0].firstChild.nodeValue;

alert("agef: "+age_frm);
}

if
(search.getElementsByTagName("age_to")[0].firstChild.nodeValue != "") {
age_to =
search.getElementsByTagName("age_to")[0].firstChild.nodeValue;

alert("aget: "+age_to);
}

if
(search.getElementsByTagName("type")[0].firstChild.nodeValue != "") {
type =
search.getElementsByTagName("type")[0].firstChild.nodeValue;

alert("type: "+type);
}

} //4

catch (e) { //5

alert("There has
been an error. The problem is that " + e.message + ". This is a '" +
e.name + "' problem.");

} //5

} //3

else

{ //6
alert("Problem retrieving
XML data")
} //6

} //2

} //1




i am parsing the code using the below parse function:

Code:

function parse(xml) {

var dom;

try {
dom = new
ActiveXObject("Microsoft.XMLDOM");
dom.async = false;
dom.loadXML(xml);
} catch (error) {
try {
var parser = new
DOMParser();
dom =
parser.parseFromString(xml, "text/xml");
delete parser;
} catch (error2) {
if (debug)
alert("XML parsing is
not supported.");
}
}

return dom;

}



no matter what i do i keep getting that search has no properties. but
the below line is correct, isn't it?
var search = dom.getElementsByTagName('search').item(0);

so, if that is correct, then the problem is the content of the
response. but, when i uncomment my errorhandling code:

//UNCOMMENT FOR ERROR CHECKING - RESPONSETEXT IN NEW WINDOW
//var doc = ajaxRequest.responseText;
// doc=doc.replace(/</g, '<').replace(/\>/g, '>');
//childWin=window.open("", "childwin");
//childWin.document.write("<pre>"+doc+"</pre>");
//childWin.document.close();

i get the below line:

<?xml version='1.0'
encoding='ISO-8859-1'?><search><sex>male</sex><agefrom>18</agefrom><ageto>100</ageto><type>sometype</type></search>


so, that is everything. i am probably overlooking something obvious
but, at this point, i need another set of eyes to point
it out.

thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,817
Latest member
AdalbertoT

Latest Threads

Top