html - Get element from external XML page using javascript? -


so i'm not great javascript, i'm trying make mail notification or sort of things.

so far i'm using gmails xml file display number of unread emails under fullcount tag. want fetch javascript , display on html page. there better way this?

so far i've come this:

html:

<!doctype html> <html>     <head>         <meta charset="utf-8">         <title>test</title>         <link rel="stylesheet" href="style.css">         <script src="gmail.js"></script>     </head>     <body onload=getgmail();>         <div id="container">             <div id="gmail">                 <p id="mail">0</p>             </div>          </div>     </body> </html> 

javascript:

function getgmail() {      //loadpage     $.get("https://username:password@mail.google.com/mail/feed/atom", function(data));      //get variable inside fullcount tags     var mailcount= document.getelementsbytagname('fullcount');      //output variable html     document.getelementbyid('mail').innerhtml = fullcount;  } 

i'm doing wrong , appreciate help! thanks

function getgmail() {      $.get("https://username:password@mail.google.com/mail/feed/atom", function(data) {         var mailcount = data.getelementsbytagname("fullcount")[0].textcontent;         document.getelementbyid('mail').innerhtml = mailcount;     );  } 

you should check out $.get() api documentation.


Comments