waf771
asked on
AJAX how to return Null values
When using responseXML to return values from an asp document it will not return a NULL value or a blank value from the database without holding up the responseXML. How can I properly handle Null values without having to have somthing in the database field. Right now I must have a value in the database field or the AJAX script does not complete the script. So how can XML / AJAX ignore the Nulls.
THE FOLLOWING IS THE AJAX:
function GetSystemEdit(SysID)
{
xmlHttp = GetXmlHttpObject();
xmlHttp.onreadystatechange = ReturnGetSystem;
xmlHttp.open('Get','Estima tesASP.asp ?action=Op enSystem&S ysID='+Sys ID, true);
xmlHttp.send(null);
}
function ReturnGetSystem()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
var xmlDoc = xmlHttp.responseXML.docume ntElement;
var System = xmlDoc.getElementsByTagNam e('System' )[0].child Nodes[0].n odeValue;
var DateEntered = xmlDoc.getElementsByTagNam e('DateEnt ered')[0]. childNodes [0].nodeVa lue;
var EnteredBy = xmlDoc.getElementsByTagNam e('Entered By')[0].ch ildNodes[0 ].nodeValu e;
var Notes = xmlDoc.getElementsByTagNam e('Notes') [0].childN odes[0].no deValue;
var RCSNotes = xmlDoc.getElementsByTagNam e('RCSNote s')[0].chi ldNodes[0] .nodeValue ;
var TaxRate = xmlDoc.getElementsByTagNam e('TaxRate ')[0].chil dNodes[0]. nodeValue;
var MU = xmlDoc.getElementsByTagNam e('MU')[0] .childNode s[0].nodeV alue;
var SysID = xmlDoc.getElementsByTagNam e('SysID') [0].childN odes[0].no deValue;
}
else
{
alert('There was a problem with the request.');
}
}
}
THE FOLLOWING IS THE ASP CODE:
Dim EstID
Dim XML
Dim System
Dim DateEntered
Dim EnteredBy
Dim TaxRate
Dim MU
SysID = CStr(Request.QueryString(" SysID"))
XML = ""
SQL = "SELECT * FROM Systems WHERE SystemID = "&SysID
set rs=Server.CreateObject("AD ODB.Record set")
rs.Open SQL, REDconnstring
XML = XML + "<root>"
XML = XML + "<System>"&rs("System")&"< /System>"
XML = XML + "<DateEntered>"&rs("DateEn tered")&"< /DateEnter ed>"
XML = XML + "<EnteredBy>"&rs("EnteredB y")&"</Ent eredBy>"
XML = XML + "<Notes>"&rs("Notes")&"</N otes>"
XML = XML + "<RCSNotes>"&rs("RCSNotes" )&"</RCSNo tes>"
'XML = XML + "<DateBid>"&rs("DateBid")& "</DateBid >"
'XML = XML + "<DateWon>"&rs("DateWon")& "</DateWon >"
XML = XML + "<TaxRate>"&rs("TaxRate")& "</TaxRate >"
XML = XML + "<MU>"&rs("MU")&"</MU>"
XML = XML + "<SysID>"&SysID&"</SysID>"
XML = XML + "</root>"
set rs = nothing
response.ContentType = "text/xml"
response.Write(XML)
.
THE FOLLOWING IS THE AJAX:
function GetSystemEdit(SysID)
{
xmlHttp = GetXmlHttpObject();
xmlHttp.onreadystatechange
xmlHttp.open('Get','Estima
xmlHttp.send(null);
}
function ReturnGetSystem()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
var xmlDoc = xmlHttp.responseXML.docume
var System = xmlDoc.getElementsByTagNam
var DateEntered = xmlDoc.getElementsByTagNam
var EnteredBy = xmlDoc.getElementsByTagNam
var Notes = xmlDoc.getElementsByTagNam
var RCSNotes = xmlDoc.getElementsByTagNam
var TaxRate = xmlDoc.getElementsByTagNam
var MU = xmlDoc.getElementsByTagNam
var SysID = xmlDoc.getElementsByTagNam
}
else
{
alert('There was a problem with the request.');
}
}
}
THE FOLLOWING IS THE ASP CODE:
Dim EstID
Dim XML
Dim System
Dim DateEntered
Dim EnteredBy
Dim TaxRate
Dim MU
SysID = CStr(Request.QueryString("
XML = ""
SQL = "SELECT * FROM Systems WHERE SystemID = "&SysID
set rs=Server.CreateObject("AD
rs.Open SQL, REDconnstring
XML = XML + "<root>"
XML = XML + "<System>"&rs("System")&"<
XML = XML + "<DateEntered>"&rs("DateEn
XML = XML + "<EnteredBy>"&rs("EnteredB
XML = XML + "<Notes>"&rs("Notes")&"</N
XML = XML + "<RCSNotes>"&rs("RCSNotes"
'XML = XML + "<DateBid>"&rs("DateBid")&
'XML = XML + "<DateWon>"&rs("DateWon")&
XML = XML + "<TaxRate>"&rs("TaxRate")&
XML = XML + "<MU>"&rs("MU")&"</MU>"
XML = XML + "<SysID>"&SysID&"</SysID>"
XML = XML + "</root>"
set rs = nothing
response.ContentType = "text/xml"
response.Write(XML)
.
ASKER
Still does not work. If the Notes field, for example, is empty in the database then the AJAX comand will not complete and nothing loads on my page, however if I put something back in that field then everything loads fine. So somehow it does not like an empty database field.
try using this:
SQL = "SELECT System,DateEntered,Entered By,Nz(Note s,'') as theNotes ,RCSNotes,DateBid,DateWon, TaxRate,MU FROM Systems WHERE SystemID = " & SysID
and instead of:
XML = XML + "<Notes>" & rs.Fields("Notes").value & "</Notes>"
use:
XML = XML + "<Notes>" & rs.Fields("theNotes").valu e & "</Notes>"
SQL = "SELECT System,DateEntered,Entered
and instead of:
XML = XML + "<Notes>" & rs.Fields("Notes").value & "</Notes>"
use:
XML = XML + "<Notes>" & rs.Fields("theNotes").valu
ASKER
That comes up with "There was a problem with the request". Can you Explain.......Nz(Notes,'') as theNotes .....to me?.
>>Can you Explain.......Nz(Notes,'') ...
Basically Nz acts as an If-Else.
http://www.techonthenet.com/access/functions/advanced/nz.php
Intead of
..., Nz(notes,'') as theNotes, ...
try:
..., IIF(notes,notes,'') as theNotes, ...
If that still doesn't work try:
..., IIF(Not isNull(notes),notes,'') as theNotes, ...
Basically Nz acts as an If-Else.
http://www.techonthenet.com/access/functions/advanced/nz.php
Intead of
..., Nz(notes,'') as theNotes, ...
try:
..., IIF(notes,notes,'') as theNotes, ...
If that still doesn't work try:
..., IIF(Not isNull(notes),notes,'') as theNotes, ...
ASKER
mmmm..I still get "There was a problem with the request". I traded out IIF for IF and it still does not seem to work... I also traded out ..., IIF(Not isNull(notes),notes,'') as theNotes, ... For just 'Notes' as well as changed ....rs.Fields("RCSNotes"). value..... back to ....rs.Fields("Notes").val ue.....and it works fine so long as there is no null, so i know the rest of my syntax is good.
ASKER
By the way I am using SQL 2005, and not Acess. That may make a diffrence.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks so much
Open in new window