?
Solved

AJAX how to return Null values

Posted on 2008-11-07
9
Medium Priority
?
398 Views
Last Modified: 2012-05-05
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)




.
0
Comment
Question by:waf771
  • 5
  • 4
9 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 22906772
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

0
 

Author Comment

by:waf771
ID: 22907116
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.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22907286
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>"
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:waf771
ID: 22907357
That comes up with "There was a problem with the request".  Can you Explain.......Nz(Notes,'') as theNotes .....to me?.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22907419
>>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, ...

0
 

Author Comment

by:waf771
ID: 22907563
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.  
0
 

Author Comment

by:waf771
ID: 22907581
By the way I am using SQL 2005, and not Acess. That may make a diffrence.
0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 22907871
Nz is for access. Try:

SQL = "SELECT System,DateEntered,EnteredBy, COALESCE(Notes,'') as theNotes ,RCSNotes,DateBid,DateWon,TaxRate,MU FROM Systems WHERE SystemID = " & SysID
0
 

Author Closing Comment

by:waf771
ID: 31514437
Thanks so much
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question