2014-01-15 125 views
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'));    
    }); 
    } 
}); 

任何帮助将受到欢迎。 谢谢。

+1

只要响应是有效的xml,url不必以'.xml'结尾 - 这就是最重要的。您可以向我们展示回复,或者向我们提供请求的工作网址吗? – Archer

+0

您是不是在服务器上设置内容类型? – epascarello

+0

网址是: “http://www.promored.com/new/modulo-xml/xml_noticias.asp?tipo="+tipo+"&publicaAgencia=S” Js函数的XML文件扩展名是在我的本地机器上测试,以读取原始文件的类似内容。 – user2770216

回答

0

即使目标文件有php扩展名,它也适用于我。

也许试试这个:

$.post("xml/noticias.xml", function(xml){ 
    $(xml).find("noticia").each(function(){ 
    $('.news-title').append($(this).attr('titulo')); 
    $('.news-text').append($(this).attr('texto'));    
    }); 
},"xml"); 

,让我知道是否可行。