0
這是我得到的AS功能。沒有被我開發。 目標是在Javascript中創建相同的功能。外部URL針對的是ASP文件,而不是XML,這是我的問題。AS功能到JS功能
var newsArray:Array = new Array(); 功能loadNews(TIPO){
xml = "http://www.promored.com/new/modulo-xml/xml_noticias.asp?tipo="+tipo+"&publicaAgencia=S";
trace(xml);
function loadXML(){
cant = this.firstChild.childNodes.length;
for (var i = 0; i<cant; i++) {
var dato = docXML.firstChild.childNodes[i];
var titulo = dato.attributes.titulo;
var texto = dato.attributes.texto;
newsArray.push({
titulo:titulo,
texto:texto
});
}
delete docXML;
if (miArray.length>0) {
gotoAndStop("cargado");
} else {
nextFrame();
}
}
var docXML = new XML();
docXML.ignoreWhite = true;
docXML.onLoad = cargaXML;
docXML.load(xml);
} loadNews(TIPO);
這是JS簡單函數,僅在URL是XML擴展時纔有效。
$.ajax({
type: "GET",
dataType: "xml",
url: "xml/noticias.xml",
success: function(xml){
$(xml).find("noticia").each(function(){
$('.news-title').append($(this).attr('titulo'));
$('.news-text').append($(this).attr('texto'));
});
}
});
任何幫助將受到歡迎。 謝謝。
只要響應是有效的xml,url不必以'.xml'結尾 - 這就是最重要的。您可以向我們展示回覆,或者向我們提供請求的工作網址嗎? – Archer
您是不是在服務器上設置內容類型? – epascarello
網址是: 「http://www.promored.com/new/modulo-xml/xml_noticias.asp?tipo="+tipo+"&publicaAgencia=S」 Js函數的XML文件擴展名是在我的本地機器上測試,以讀取原始文件的類似內容。 – user2770216