Last active
April 4, 2017 01:14
-
-
Save kkeeth/a17e3aeff0914de4a3110b0c22a41509 to your computer and use it in GitHub Desktop.
Ajaxのデモソースコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQueryを使ったパターン | |
$.ajax({ | |
url : './sample_rss.xml', | |
dataType: 'xml', | |
success : function(data) { | |
$('dl').html(''); | |
$('item', data).each(function() { | |
$('dl').append('<dt><a href="' | |
+ $('link', this).text() | |
+ '">' | |
+ $('title', this).text() | |
+ '</a></dt><dd>' | |
+ $('discription', this).text() | |
+ '</dd>' | |
); | |
}); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<rss version="2.0"> | |
<channel> | |
<title>hogehoge</title> | |
<link>http://hogehoge.main.jp</link> | |
<pubData>Fri, 21 Aug 2009 07:59:00 +0900</pubData> | |
<item> | |
<title>サブタイトル1</title> | |
<pubData>Fri, 21 Aug 2009 07:59:00 +0900</pubData> | |
<link>http://hogehoge.sub1.jp</link> | |
<description>サブテキスト1</description> | |
</item> | |
<item> | |
<title>サブタイトル2</title> | |
<pubData>Fri, 21 Aug 2009 07:59:00 +0900</pubData> | |
<link>http://hogehoge.sub2.jp</link> | |
<description>サブテキスト2</description> | |
</item> | |
<item> | |
<title>サブタイトル3</title> | |
<pubData>Fri, 21 Aug 2009 07:59:00 +0900</pubData> | |
<link>http://hogehoge.sub3.jp</link> | |
<description>サブテキスト3</description> | |
</item> | |
</channel> | |
</rss> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 素のJavaScriptパターン | |
function ajax() { | |
var xmlHttp = new XMLHttpRequest(); | |
xmlHttp.onreadystatechange = function() { | |
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { | |
comsole.log(xmlHttp.responseText); | |
} | |
}; | |
xmlHttp.open("GET", "URL", true); | |
xmlHttp.send(null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment