検索結果: タグ「Ajax」
jQueryのAjaxを使ってRSSフィードを読み込むとIE7でエラーに
2008年12月21日 15:53 » オープンソース
jQueryのAjaxを使ってRSSフィードを読み込むとIE7でエラーになった。
該当のフィードはあるCMSによって動的に作成されたもので、RSSのバージョンは2.0。
マイクロソフトのブログ(http://blogs.msdn.com/rssteam/articles/PublishersGuide.aspx)によると、IE7でRSS2.0のフィードを正しく表示させるには、MIMEタイプを
text/xml(推奨)
か、もしくは
application/rss+xml
にしてくださいとある。
このCMSではapplication/rss+xmlになっていたので、ためしにtext/xmlに変えてみたところエラーが消えた。
確認のためにtext/xml、application/rss+xml、application/xmlの3パターンで読み込むサンプルを作成。
$.ajax({
type: 'POST',
url: '/samples/rss/' + type + '.php',
dataType: 'xml',
success: function (response) {
・・・
},
error: function (xmlhttp, textStatus, errorThrown) {
alert("xmlhttp.status: " + xmlhttp.status + ", \n" +
"textStatus: " + textStatus + ", \n" +
"errorThrown: " + errorThrown);
}
});
のようにしてエラーを表示させてみると、やはりapplication/rss+xmlの時だけ
xmlhttp.status: 200
textStatus: parsererror
errorThrown: undefined
というメッセージが出た。
PrototypeのAjax.RequestとresponseXMLを使ったAjax通信
2008年6月20日 17:32 » オープンソース
Event.observe($('someButton'), 'click',
function(e) {
new Ajax.Request('myxml.php',
{ method:'post',
parameters:
{ param1: "foo", param2: "bar" },
onSuccess: function(transport){
var res = transport.responseXML;
var msg = res.getElementsByTagName('msg')[0] ;
alert(msg.firstChild.nodeValue);
},
onFailure: function(){ alert('Error: could not save layout.') }
});
});
header("Content-Type: application/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo "\n";
echo "<msg>";
echo "<![CDATA[";
echo $_POST['param1'] . ',' . $_POST['param2'];
echo "]]>";
echo "</msg>";
Ads
4plus Link
Profile
Junya Sano
CTO at 4plus Inc.
B.S. degree in Computer Science at Oregon State University.
Specialty in web development, especially LAMP.

