Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So I'm not that great with javascript, but I'm trying to make a mail notification or this sort of things.

So far I'm using gmails xml file that will display the number of unread emails under a fullcount tag. I want to fetch this with javascript and display it on a html page. Is there a better way to do this?

So far I've come up with 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:[email protected]/mail/feed/atom", function(data));

    //get variable inside fullcount tags
    var mailcount= document.getElementsByTagName('fullcount');

    //output variable to html
    document.getElementById('mail').innerHTML = fullcount;

}

I'm probably doing it completely wrong and I would appreciate your help! thanks

share|improve this question

1 Answer

function getgmail() {

    $.get("https://USERNAME:[email protected]/mail/feed/atom", function(data) {
        var mailcount = data.getElementsByTagName("fullcount")[0].textContent;
        document.getElementById('mail').innerHTML = mailcount;
    );

}

You should check out $.get() API documentation.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.