【问题标题】:AS2 function to JS functionAS2 函数转 JS 函数
【发布时间】:2014-02-04 03:13:55
【问题描述】:

这是我拥有的 AS 功能。不是我开发的。 目标是在 Javascript 中创建相同的函数。外部 URL 以 ASP 文件而不是 XML 为目标,这是我的问题。


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);

} 加载新闻(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 结尾 - 这才是最重要的。您能否向我们展示响应,或者为我们提供请求的有效网址?
  • 你不是在服务器上设置内容类型吗?
  • 网址是:"promored.com/new/modulo-xml/…" Js函数上的XML文件扩展名,是在我的本地机器上测试的,读取原文件类似的内容。
  • 我可以在上面的代码中看到该 url,但没有有效的 tipo 值,它不适合我们。
  • 您能否向我们提供一个完整的 url(值为tipo),或者发布 xml 以便我们查看?如果没有其中之一,我们将无法为您提供帮助。

标签: javascript jquery xml actionscript


【解决方案1】:

即使目标文件具有 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");

如果可行,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-30
    相关资源
    最近更新 更多