Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. how to handle NULL from a data request using QML doc.responseXML.documentElement
Forum Updated to NodeBB v4.3 + New Features

how to handle NULL from a data request using QML doc.responseXML.documentElement

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
9 Posts 2 Posters 1.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    biskero
    wrote on last edited by
    #1

    Hello,

    I am trying to handle NULL from a data request using QML doc.responseXML.documentElement:

    if (doc.readyState === XMLHttpRequest.DONE) {
                    //Check is not NULL
                    if(!doc.responseXML.documentElement) {
                        var a = doc.responseXML.documentElement;
    
    
                    }
    }
    

    but I get that an error: TypeError: Value is null and could not be converted to an object
    So how do I catch null value coming from the doc.responseXML.documentElement ?

    thx

    raven-worxR 1 Reply Last reply
    0
    • B biskero

      Hello,

      I am trying to handle NULL from a data request using QML doc.responseXML.documentElement:

      if (doc.readyState === XMLHttpRequest.DONE) {
                      //Check is not NULL
                      if(!doc.responseXML.documentElement) {
                          var a = doc.responseXML.documentElement;
      
      
                      }
      }
      

      but I get that an error: TypeError: Value is null and could not be converted to an object
      So how do I catch null value coming from the doc.responseXML.documentElement ?

      thx

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @biskero
      please show the whole code handling your XMLHttpRequest

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • B Offline
        B Offline
        biskero
        wrote on last edited by
        #3
        This post is deleted!
        B 1 Reply Last reply
        0
        • B biskero

          This post is deleted!

          B Offline
          B Offline
          biskero
          wrote on last edited by
          #4

          This is the code, data is received correctly but after the check DONE, I want to make sure if not NULL but I get the error:
          TypeError: Value is null and could not be converted to an object

          on the var a = doc.responseXML.documentElement; code line

          if (doc.readyState === XMLHttpRequest.DONE) {
                          //Check is not NULL
                          if(!doc.responseXML.documentElement) {
                              var a = doc.responseXML.documentElement;
          for (var ii = 0; ii < a.childNodes.length; ++ii) {
                                  //showRequestInfo(a.childNodes[ii].nodeName);
                                  if(a.childNodes[ii].nodeName === "light") {
                                      console.log("a="+a.childNodes[ii].childNodes[0].nodeValue);
                                  }
          }
          }
          
          raven-worxR 1 Reply Last reply
          0
          • B biskero

            This is the code, data is received correctly but after the check DONE, I want to make sure if not NULL but I get the error:
            TypeError: Value is null and could not be converted to an object

            on the var a = doc.responseXML.documentElement; code line

            if (doc.readyState === XMLHttpRequest.DONE) {
                            //Check is not NULL
                            if(!doc.responseXML.documentElement) {
                                var a = doc.responseXML.documentElement;
            for (var ii = 0; ii < a.childNodes.length; ++ii) {
                                    //showRequestInfo(a.childNodes[ii].nodeName);
                                    if(a.childNodes[ii].nodeName === "light") {
                                        console.log("a="+a.childNodes[ii].childNodes[0].nodeValue);
                                    }
            }
            }
            
            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            @biskero
            also the code before that block

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • B Offline
              B Offline
              biskero
              wrote on last edited by
              #6
              if (doc.readyState === XMLHttpRequest.LOADING) {
                              //Do something while loading
              
                          } else if (doc.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
                              //showRequestInfo("Headers -->");
                              //showRequestInfo(doc.getAllResponseHeaders ());
                              //showRequestInfo("Last modified -->");
                              //showRequestInfo(doc.getResponseHeader ("Last-Modified"));
              
                          } else if (doc.readyState === XMLHttpRequest.DONE) {
                              //Check is not NULL
                              if(!doc.responseXML.documentElement) {
                                  var a = doc.responseXML.documentElement;
              for (var ii = 0; ii < a.childNodes.length; ++ii) {
                                      //showRequestInfo(a.childNodes[ii].nodeName);
                                      if(a.childNodes[ii].nodeName === "light") {
                                          console.log("a="+a.childNodes[ii].childNodes[0].nodeValue);
                                      }
              }
              }
              
              raven-worxR 1 Reply Last reply
              0
              • B biskero
                if (doc.readyState === XMLHttpRequest.LOADING) {
                                //Do something while loading
                
                            } else if (doc.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
                                //showRequestInfo("Headers -->");
                                //showRequestInfo(doc.getAllResponseHeaders ());
                                //showRequestInfo("Last modified -->");
                                //showRequestInfo(doc.getResponseHeader ("Last-Modified"));
                
                            } else if (doc.readyState === XMLHttpRequest.DONE) {
                                //Check is not NULL
                                if(!doc.responseXML.documentElement) {
                                    var a = doc.responseXML.documentElement;
                for (var ii = 0; ii < a.childNodes.length; ++ii) {
                                        //showRequestInfo(a.childNodes[ii].nodeName);
                                        if(a.childNodes[ii].nodeName === "light") {
                                            console.log("a="+a.childNodes[ii].childNodes[0].nodeValue);
                                        }
                }
                }
                
                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by raven-worx
                #7

                @biskero
                ok once more.
                I am not interested in any more detail implementations from the inside of your function, showing code beyond the point you want to do your check isnt relevant.
                I want to see the code beginning from where you create the XMLHttpRequest object.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  biskero
                  wrote on last edited by
                  #8

                  the code come from this example

                   MouseArea {
                              id: mouseArea
                              anchors.fill: parent
                              onClicked: {
                                  log.text = ""
                                  console.log("\n")
                  
                                  var doc = new XMLHttpRequest();
                                  doc.onreadystatechange = function() {
                                      if (doc.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
                                          showRequestInfo("Headers -->");
                                          showRequestInfo(doc.getAllResponseHeaders ());
                                          showRequestInfo("Last modified -->");
                                          showRequestInfo(doc.getResponseHeader ("Last-Modified"));
                  
                                      } else if (doc.readyState == XMLHttpRequest.DONE) {
                                          var a = doc.responseXML.documentElement;
                                          for (var ii = 0; ii < a.childNodes.length; ++ii) {
                                              showRequestInfo(a.childNodes[ii].nodeName);
                                          }
                                          showRequestInfo("Headers -->");
                                          showRequestInfo(doc.getAllResponseHeaders ());
                                          showRequestInfo("Last modified -->");
                                          showRequestInfo(doc.getResponseHeader ("Last-Modified"));
                                      }
                                  }
                  
                                  doc.open("GET", "data.xml");
                                  doc.send();
                              }
                          }
                  

                  I just add the code to check the if object is not NULL

                  if(!doc.responseXML.documentElement)
                  
                  raven-worxR 1 Reply Last reply
                  0
                  • B biskero

                    the code come from this example

                     MouseArea {
                                id: mouseArea
                                anchors.fill: parent
                                onClicked: {
                                    log.text = ""
                                    console.log("\n")
                    
                                    var doc = new XMLHttpRequest();
                                    doc.onreadystatechange = function() {
                                        if (doc.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
                                            showRequestInfo("Headers -->");
                                            showRequestInfo(doc.getAllResponseHeaders ());
                                            showRequestInfo("Last modified -->");
                                            showRequestInfo(doc.getResponseHeader ("Last-Modified"));
                    
                                        } else if (doc.readyState == XMLHttpRequest.DONE) {
                                            var a = doc.responseXML.documentElement;
                                            for (var ii = 0; ii < a.childNodes.length; ++ii) {
                                                showRequestInfo(a.childNodes[ii].nodeName);
                                            }
                                            showRequestInfo("Headers -->");
                                            showRequestInfo(doc.getAllResponseHeaders ());
                                            showRequestInfo("Last modified -->");
                                            showRequestInfo(doc.getResponseHeader ("Last-Modified"));
                                        }
                                    }
                    
                                    doc.open("GET", "data.xml");
                                    doc.send();
                                }
                            }
                    

                    I just add the code to check the if object is not NULL

                    if(!doc.responseXML.documentElement)
                    
                    raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #9

                    @biskero

                    1. try console.log(doc.responseXML.documentElement) and console.log(typeof doc.responseXML.documentElement) and check the console output, it might give some help
                    2. where does this file come from? its important what the Content-Type is of the response.
                    3. try doc.responseXML.documentElement == null or doc.responseXML.documentElement == undefined

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved