Skip to content

twitter.phpで取ってきたXMLを表示させるJS

Yoshiaki Nakao edited this page Mar 29, 2016 · 1 revision

<div id=id1>コメント読み込み中・・・</div> <div id=id2>コメント読み込み中・・・</div> <script> var v_s1 = "ipad";//検索ワード1 var v_s2 = "iphone";//検索ワード2 //増やしてもOK var v_s = "twitter.php?q=%23"; var v_load_xml1 = v_s + v_s1; var v_load_xml2 = v_s + v_s2; var v_all = 0,xmlObj; function f_load() {

f_load2(v_load_xml1, "id1");//id1はid名 f_load2(v_load_xml2, "id2");//増やしてもOK

} function f_load2(v_load_xml, v_id) {

var httpObj = new XMLHttpRequest(); httpObj.open("GET", v_load_xml, true); httpObj.send(null); httpObj.onreadystatechange = function () {

if ((httpObj.readyState == 4) && (httpObj.status == 200)) {

xmlObj = httpObj.responseXML; v_all = xmlObj.getElementsByTagName('entry').length; if (v_all > 0) {

f_comment_set(v_id);

}

}

}

} function f_comment_set(v_id) {

var v_html=""; for (i = 0; i < v_all; i++) {

var v_name = xmlObj.getElementsByTagName('entry')[i].childNodes[11].childNodes[0].childNodes[0].nodeValue; var v_tit=xmlObj.getElementsByTagName('entry')[i].childNodes[4].childNodes[0].nodeValue; v_html += v_name + v_tit;

} document.getElementById(v_id).innerHTML = v_html;

} f_load(); </script>

Clone this wiki locally