Link to home
Start Free TrialLog in
Avatar of waf771
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','EstimatesASP.asp?action=OpenSystem&SysID='+SysID, true);
        xmlHttp.send(null);
}


function ReturnGetSystem()
{

 if (xmlHttp.readyState == 4)
        {
             
            if (xmlHttp.status == 200)
          {
                    
                  var xmlDoc = xmlHttp.responseXML.documentElement;
                  
                  var System = xmlDoc.getElementsByTagName('System')[0].childNodes[0].nodeValue;
                  var DateEntered = xmlDoc.getElementsByTagName('DateEntered')[0].childNodes[0].nodeValue;
                var EnteredBy = xmlDoc.getElementsByTagName('EnteredBy')[0].childNodes[0].nodeValue;
                  var Notes = xmlDoc.getElementsByTagName('Notes')[0].childNodes[0].nodeValue;
                  var RCSNotes = xmlDoc.getElementsByTagName('RCSNotes')[0].childNodes[0].nodeValue;
                  var TaxRate = xmlDoc.getElementsByTagName('TaxRate')[0].childNodes[0].nodeValue;
                  var MU = xmlDoc.getElementsByTagName('MU')[0].childNodes[0].nodeValue;
                  var SysID = xmlDoc.getElementsByTagName('SysID')[0].childNodes[0].nodeValue;
                  

         }
             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("ADODB.Recordset")
      rs.Open SQL, REDconnstring
      
      
      XML = XML + "<root>"      
      XML = XML + "<System>"&rs("System")&"</System>"
      XML = XML + "<DateEntered>"&rs("DateEntered")&"</DateEntered>"
      XML = XML + "<EnteredBy>"&rs("EnteredBy")&"</EnteredBy>"
      XML = XML + "<Notes>"&rs("Notes")&"</Notes>"
      XML = XML + "<RCSNotes>"&rs("RCSNotes")&"</RCSNotes>"
      '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)




.
Avatar of hielo
hielo
Flag of Wallis and Futuna image

try:
XML = XML + "<root>"      
      XML = XML + "<System>" & rs.Fields("System").value & "</System>"
      XML = XML + "<DateEntered>" & rs.Fields("DateEntered").value & "</DateEntered>"
      XML = XML + "<EnteredBy>" & rs.Fields("EnteredBy").value & "</EnteredBy>"
      XML = XML + "<Notes>" & rs.Fields("Notes").value & "</Notes>"
      XML = XML + "<RCSNotes>" & rs.Fields("RCSNotes").value & "</RCSNotes>"
      'XML = XML + "<DateBid>" & rs.Fields("DateBid").value & "</DateBid>"
      'XML = XML + "<DateWon>" & rs.Fields("DateWon").value & "</DateWon>"
      XML = XML + "<TaxRate>" & rs.Fields("TaxRate").value & "</TaxRate>"
      XML = XML + "<MU>" & rs.Fields("MU").value & "</MU>"
      XML = XML + "<SysID>" & SysID & "</SysID>"
                     XML = XML + "</root>"

Open in new window

Avatar of waf771
waf771

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,EnteredBy,Nz(Notes,'') 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").value & "</Notes>"
Avatar of waf771

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, ...

Avatar of waf771

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").value.....and it works fine so long as there is no null,  so i know the rest of my syntax is good.  
Avatar of waf771

ASKER

By the way I am using SQL 2005, and not Acess. That may make a diffrence.
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of waf771

ASKER

Thanks so much