20i Reseller Hosting

Display xml result javascript

Discussion in 'Scripts and Coding' started by dee, Jan 22, 2019.

  1. dee

    dee Well-Known Member Acorn Supporter

    Joined:
    May 2013
    Posts:
    1,923
    Likes Received:
    225
    Hi all,

    @RobM very kindly helped me previously on a project here with javascript. Im trying to add display functionality to the project now a while later. Im displaying foscam security cams in a private website with the ability to set and disable the motion detect alarm via the webpage . If the alarm triggers it then texts and emails screengrabs to a couple phones and email accounts.Thats all working fab.

    Basically, i'd like to be able to display the alarm status on the same page.I can call a cgi url which returns the alarm status in xml format like this

    Code:
    <CGI_Result>
       <result>0</result>
       <isEnable>1</isEnable>
       <linkage>2</linkage>
       <snapInterval>2</snapInterval>
       <sensitivity>4</sensitivity>
       <triggerInterval>15</triggerInterval>
       <schedule0>281474976710655</schedule0>
       <schedule1>281474976710655</schedule1>
       <schedule2>281474976710655</schedule2>
       <schedule3>281474976710655</schedule3>
       <schedule4>281474976710655</schedule4>
       <schedule5>281474976710655</schedule5>
       <schedule6>281474976710655</schedule6>
    </CGI_Result>
    
    What id like to be able to do is check the <isEnable>1</isEnable> flag and if its 1 display 'alarm on' or if its 0 display 'alarm off'

    Ive googled but not come up with much. Any help or pointing in right direction appreciated.
     
  2. Domain Forum

    Acorn Domains Elite Member

    Joined:
    1999
    Messages:
    Many
    Likes Received:
    Lots
    articles.co.uk
     
  3. RobM

    RobM Retired Member

    Joined:
    Mar 2012
    Posts:
    3,289
    Likes Received:
    469
    Are you using jquery? Is this something that only needs to be run when the page is loaded or will you be polling it on a loaded page?
     
  4. dee

    dee Well-Known Member Acorn Supporter

    Joined:
    May 2013
    Posts:
    1,923
    Likes Received:
    225
    Morning Rob. Yep, J query. Whatevers easy to be honest. On page load is fine. I can always refresh to check status
     
  5. RobM

    RobM Retired Member

    Joined:
    Mar 2012
    Posts:
    3,289
    Likes Received:
    469
    Ok assuming you can get the data into a variable with jquery you can use the parseXML function eg:

    var xml= data,
    xmlDoc=$.parseXML(xml),
    $xml=$(xmlDoc),
    $enabled = $xml.find("isEnable").text();

    You can see an example at http://hostedchasing.com/test.php
     
    • Winner Winner x 1
  6. dee

    dee Well-Known Member Acorn Supporter

    Joined:
    May 2013
    Posts:
    1,923
    Likes Received:
    225
    Thanks @RobM . Brilliant and above as usual. Thank you . Appreciated. I'll give that a whirl.