0

So, I would like to know how to parse an xml document with JavaScript.

I've got it working in php (view below)

<?php
$xmlGmailFeed = file_get_contents("https://gmail_username:[email protected]/mail/feed/atom/");
$unreadMessages = $xmlGmailFeed->fullcount;
echo $unreadMessages;
?>

But the only thing with this, is that it's running using the server's IP address and doesnt let users login to their gmail. It pops up saying that there was a suspicious login attempt on their account. So what Id like to know is how I would be able to do the same thing, but run it from the hosts computer. I was thinking javascript to do it? But please let me know if theres a better way!

Edit:

Heres the code that im using..

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
<script>
$.ajax({
  type: "GET",
  url: "https://mail.google.com/mail/feed/atom.",
  dataType: "xml",
  crossDomain: true,
  success: parseXml
});

function parseXml(xml)
{
  var results = $(xml).find("fullcount").text();
  alert(results);
}
</script>

Here's a screen shot of my problem:

http://cbog.co.nr/SC.php?img=Admin/AE0BCBAA4F532BC69A932E5DDD8F14F2

and you can see for yourself, live at:

http://cbogausch.com/test.php

1 Answer 1

3

I believe you can just use a DOMParser. jQuery also offers .parseXML() if you're willing to use it.

Sign up to request clarification or add additional context in comments.

5 Comments

ohhh alright.. thanks a ton!! I'll get looking into this and post the code after I get everything working.
Heres the code that im using.. <script src="ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script> <script> $.ajax({ type: "GET", url: "mail.google.com/mail/feed/atom.", dataType: "xml", crossDomain: true, success: parseXml }); function parseXml(xml) { var results = $(xml).find("fullcount").text(); alert(results); } </script> Here's a screen shot of my problem: cbog.co.nr/SC.php?img=Admin/AE0BCBAA4F532BC69A932E5DDD8F14F2 and you can see for yourself at cbogausch.com/test.php
@Chris_Bogausch That is a cross-domain problem.
I kinda figured.. Any idea how to overcome? I've been trying TONS of things for the last half hour or so..
@Chris_Bogausch You would have to look into the documentation surrounding that particular feed. I've no experience with it so I can't really say.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.