国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP ?? ?? ???? AJAX RSS ??

AJAX RSS ??

RSS ??? RSS ??? ?? ? ?????.

?:

?? ???? ? ???? ?? ??? ??? RSS ???? ?? ? ?? RSS ??? ?????.

? ?? ? ???? ?????.

  • HTML ?? ???

  • PHP ??

  • XML ??


HTML ?? ???

???? ? ???? ???? RSS-feed? ???? "showRSS()"?? ??? ?????. ? ??? "onchange" ???? ?? ?????:

?? ??? 1.php ??

<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)(php.cn)</title>
<script>
function showRSS(str)
{
	//檢查是否有 RSS-feed 被選擇
	if (str.length==0)
	{ 
		document.getElementById("rssOutput").innerHTML="";
		return;
		}
	//創(chuàng)建 XMLHttpRequest 對象
	if (window.XMLHttpRequest)
	{
		// IE7+, Firefox, Chrome, Opera, Safari 瀏覽器執(zhí)行代碼
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// IE6, IE5 瀏覽器執(zhí)行代碼
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	//創(chuàng)建在服務器響應就緒時執(zhí)行的函數(shù)
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("rssOutput").innerHTML=xmlhttp.responseText;
		}
	}
	//向服務器上的文件發(fā)送請求
	xmlhttp.open("GET","2.php?q="+str,true);
	xmlhttp.send();
}
</script>
</head>
<body>
<form>
<!-- 在域的內(nèi)容改變時觸發(fā)onchange 事件 -->
<select onchange="showRSS(this.value)">
<option value="">選擇一個 RSS-feed:</option>
<option value="rss">讀取 RSS 數(shù)據(jù)</option>
</select>
</form>
<br>
<div id="rssOutput">RSS-feed 數(shù)據(jù)列表...</div>
</body>
</html>

? HTML ????? ???? ?? ??? ?? ??? HTML ??? ???? ????.

?? ?? ??? ??? ????.

  • ???? ???? ???? ??? ???? ???? ??????.

  • ???? ????? showRSS() ??? ?????.

  • ?? ???? "rssOutput"??? ??? <div>? ????. showRSS() ???? ??? ???? ?? ?? ???? ?????.

showRSS() ??? ?? ??? ?????.

  • RSS ??? ?????? ??

  • XMLHttpRequest ?? ??

  • ?? ??? ???? ???? ?? ??

  • ??? ?? ??? ????

  • URL(???? ??? ?? ??) ?? ??? ????(q)? ?????


PHP ??

??? JavaScript? ?? ??? ?? ???? "2.php"?? ??? PHP ?????.

?? 2.php ?? ??

<?php
// rss 文件地址
$xml="3.xml";
//創(chuàng)建一個新的 XML DOM 對象
$xmlDoc = new DOMDocument();
//創(chuàng)建一個新的 XML DOM 對象
$xmlDoc->load($xml);

// 從 "<channel>" 中讀取元素
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
$channel_title = $channel->getElementsByTagName('title')
->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName('link')
->item(0)->childNodes->item(0)->nodeValue;
$channel_desc = $channel->getElementsByTagName('description')
->item(0)->childNodes->item(0)->nodeValue;

// 輸出 "<channel>" 中的元素
echo("<p><a href='" . $channel_link
  . "'>" . $channel_title . "</a>");
echo("<br>");
echo($channel_desc . "</p>");

// 輸出 "<item>" 中的元素
$x=$xmlDoc->getElementsByTagName('item');
for ($i=0; $i<=1; $i++) {
	$item_title=$x->item($i)->getElementsByTagName('title')
	->item(0)->childNodes->item(0)->nodeValue;
	$item_link=$x->item($i)->getElementsByTagName('link')
	->item(0)->childNodes->item(0)->nodeValue;
	$item_desc=$x->item($i)->getElementsByTagName('description')
	->item(0)->childNodes->item(0)->nodeValue;
	echo ("<p><a href='" . $item_link
	. "'>" . $item_title . "</a>");
	echo ("<br>");
	echo ($item_desc . "</p>");
}
?>

RSS ?? ??? JavaScript?? PHP ??? ???? ??? ????

  • ?? RSS ??? ???

  • ? XML DOM ?? ???

  • xml ??? RSS ?? ??

  • ?? ???? ?? ?? ? ??

  • ?? ???? ?? ?? ? ??


XML ??

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
  <title>php教程</title>
  <link>http://miracleart.cn</link>
  <description>學的不僅技術(shù),更新夢想?。?lt;/description>
  <item>
    <title>RSS 教程</title>
    <link>http://miracleart.cn/rss/rss-tutorial.html</link>
    <description>通過使用 RSS,您可以有選擇地瀏覽您感興趣的以及與您的工作相關(guān)的新聞</description>
  </item>
  <item>
    <title>XML 教程</title>
    <link>http://miracleart.cn/xml/xml-tutorial.html</link>
    <description>XML 指可擴展標記語言(eXtensible Markup Language)</description>
  </item>
</channel>

</rss>

?? ??

? ???? ?? ?? ?? ???? ?????.

  • ?? ??

  • onkeyup ??? : ??? ?? ??? ? ??? ? ??

  • ?? ??, ?? ? ??

  • ??? ?? ?? ??? ?? ??? ??? ? ???? ??? AJAX XMLHttpRequest ?? ??: ?? ??? 1-5? ?????

  • HTML DOM getElementById() ???: ??? ID? ?? ? ?? ??? ?? ??? ?????.

XML ?? ??

  • XML DOM ?? ??

  • XML ??? ? XML DOM ??? ??

  • ?? ??? ?? ?? ???? ??: getElementsByTagName ()

  • ??? ? ?? ?? ??? ?????: HTML DOM item() ???

???? ??
||
<html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script> function showRSS(str) { //檢查是否有 RSS-feed 被選擇 if (str.length==0) { document.getElementById("rssOutput").innerHTML=""; return; } //創(chuàng)建 XMLHttpRequest 對象 if (window.XMLHttpRequest) { // IE7+, Firefox, Chrome, Opera, Safari 瀏覽器執(zhí)行代碼 xmlhttp=new XMLHttpRequest(); } else { // IE6, IE5 瀏覽器執(zhí)行代碼 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } //創(chuàng)建在服務器響應就緒時執(zhí)行的函數(shù) xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("rssOutput").innerHTML=xmlhttp.responseText; } } //向服務器上的文件發(fā)送請求 xmlhttp.open("GET","2.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <form> <!-- 在域的內(nèi)容改變時觸發(fā)onchange 事件 --> <select onchange="showRSS(this.value)"> <option value="">選擇一個 RSS-feed:</option> <option value="rss">讀取 RSS 數(shù)據(jù)</option> </select> </form> <br> <div id="rssOutput">RSS-feed 數(shù)據(jù)列表...</div> </body> </html>