Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. variable undefined

variable undefined

Scheduled Pinned Locked Moved JavaScript
questiontoolsxml
4 Posts 3 Posters 0 Views 1 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.
  • W Offline
    W Offline
    wfzen
    wrote on last edited by
    #1

    I want to extract a video name from XML and put it in the URL parameter. I copied the XML reading code from w3school. See below:

    //var videoName; the name of the video
    var tPath = ... the URL to the XML
    var var2 = ... the filename of an XML
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
    myFunction(this);
    }
    };
    xmlhttp.open("GET", tPath, true);
    xmlhttp.send();
    function myFunction(xml) {
    var x, xmlDoc, videoName;
    xmlDoc = xml.responseXML;
    x = xmlDoc.getElementsByTagName("videoName")[0];
    videoName = (x.textContent);
    alert (videoName);
    }
    var playerURL = "http://" + getCookie("MediaServerGeneral") + "/IVP/demo.htm?XMLName=" + var2 + "&MediaFileName=" + videoName;

    I see the name of the video in alert. but the playerURL has videoName shown as undefined. my XML is like this, and I'm trying to pick up "videoName.mp4":

    videoName.mp4
    

    What is wrong with the script? Thanks,

    L R 2 Replies Last reply
    0
    • W wfzen

      I want to extract a video name from XML and put it in the URL parameter. I copied the XML reading code from w3school. See below:

      //var videoName; the name of the video
      var tPath = ... the URL to the XML
      var var2 = ... the filename of an XML
      var xmlhttp = new XMLHttpRequest();
      xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
      myFunction(this);
      }
      };
      xmlhttp.open("GET", tPath, true);
      xmlhttp.send();
      function myFunction(xml) {
      var x, xmlDoc, videoName;
      xmlDoc = xml.responseXML;
      x = xmlDoc.getElementsByTagName("videoName")[0];
      videoName = (x.textContent);
      alert (videoName);
      }
      var playerURL = "http://" + getCookie("MediaServerGeneral") + "/IVP/demo.htm?XMLName=" + var2 + "&MediaFileName=" + videoName;

      I see the name of the video in alert. but the playerURL has videoName shown as undefined. my XML is like this, and I'm trying to pick up "videoName.mp4":

      videoName.mp4
      

      What is wrong with the script? Thanks,

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See XML DOM getElementsByTagName() Method[^], I think you need to go one level further to get the value.

      1 Reply Last reply
      0
      • W wfzen

        I want to extract a video name from XML and put it in the URL parameter. I copied the XML reading code from w3school. See below:

        //var videoName; the name of the video
        var tPath = ... the URL to the XML
        var var2 = ... the filename of an XML
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
        myFunction(this);
        }
        };
        xmlhttp.open("GET", tPath, true);
        xmlhttp.send();
        function myFunction(xml) {
        var x, xmlDoc, videoName;
        xmlDoc = xml.responseXML;
        x = xmlDoc.getElementsByTagName("videoName")[0];
        videoName = (x.textContent);
        alert (videoName);
        }
        var playerURL = "http://" + getCookie("MediaServerGeneral") + "/IVP/demo.htm?XMLName=" + var2 + "&MediaFileName=" + videoName;

        I see the name of the video in alert. but the playerURL has videoName shown as undefined. my XML is like this, and I'm trying to pick up "videoName.mp4":

        videoName.mp4
        

        What is wrong with the script? Thanks,

        R Offline
        R Offline
        Rahul VB
        wrote on last edited by
        #3

        Just try to fetch the value of "x" in the below code outside "myFunction"

        x = xmlDoc.getElementsByTagName("videoName")[0];

        I am wondering, if the value of "x" is dying out. I also cant see the closing braces of "myFunction" or no return value of "x" from the function. Is the below code a part of "myFunction" ?

        var x, xmlDoc, videoName;
        xmlDoc = xml.responseXML;
        x = xmlDoc.getElementsByTagName("videoName")[0];
        videoName = (x.textContent);
        alert (videoName);

        var playerURL = "http://" + getCookie("MediaServerGeneral") + "/IVP/demo.htm?XMLName=" + var2 + "&MediaFileName=" + videoName;

        If so, just try out reading the value of the element out side the function and see. Please let me know the result once. Thanks

        W 1 Reply Last reply
        0
        • R Rahul VB

          Just try to fetch the value of "x" in the below code outside "myFunction"

          x = xmlDoc.getElementsByTagName("videoName")[0];

          I am wondering, if the value of "x" is dying out. I also cant see the closing braces of "myFunction" or no return value of "x" from the function. Is the below code a part of "myFunction" ?

          var x, xmlDoc, videoName;
          xmlDoc = xml.responseXML;
          x = xmlDoc.getElementsByTagName("videoName")[0];
          videoName = (x.textContent);
          alert (videoName);

          var playerURL = "http://" + getCookie("MediaServerGeneral") + "/IVP/demo.htm?XMLName=" + var2 + "&MediaFileName=" + videoName;

          If so, just try out reading the value of the element out side the function and see. Please let me know the result once. Thanks

          W Offline
          W Offline
          wfzen
          wrote on last edited by
          #4

          Thank you for your help. I forgot to copy the } after the alert(videoName). So myFunction ends after alert. var playerURL... is not part of the function. I'm trying to take the script out of the function. I'll post back the result.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups