我有一块代码来获取gmail的未读计数。它正在使用jQuery,我想知道如何在没有JavaScript库的情况下使用JavaScript。
$.ajax({
type: "GET",
url: "https://mail.google.com/mail/feed/atom",
dataType: "xml",
success: parseXml
});
function parseXml(xml)
{
var result = $(xml).find("fullcount").text();
alert("count:" + result);
}
尝试此
var xmlhttp=new XMLHttpRequest();
xmlhttp.setRequestHeader("Access-Control-Allow-Origin","https://mail.google.com");
xmlhttp.open("POST","https://mail.google.com/mail/feed/atom",false,"username","pwd");
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var mailCount=xmlDoc.getElementsByTagName("entry").length;
好的,已解决
xhrGmail = new XMLHttpRequest();
xhrGmail.open('GET','https://mail.google.com/mail/feed/atom')
xhrGmail.onload = function() { console.log(xhrGmail.responseText.split("<fullcount>") [1].split("</fullcount>")[0]) }
xhrGmail.send(null);