本文介绍了获取远程XML文件中的AJAX和用jQuery解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个HTML5应用程序的BlackBerry OS 5 +。

I'm developing a HTML5 application for Blackberry OS 5+.

我使用jQuery下载和XML文件,并显示使用该功能:

I'm using jQuery to download and XML file and show it using this function:

$(document).ready(function()
{
    $.ajax({
        type: "GET",
        url: "http://xxx.com/yyy/mTop",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('item').each(function(){
                var tipo = $(this).find('tipo').text();
                var porcentaje = $(this).find('porcentaje').text();
                $('<div class="items"></div>').html('<p>' + tipo + ' - ' + porcentaje + '</p>').appendTo('#page-wrap');
            });
        }
    });
});

不过,我得到这个错误:

But I'm getting this error:

XMLHttpRequest cannot load http://xxx.com/yyy/mTop. Origin file:// is not allowed by Access-Control-Allow-Origin.

我如何解析远程XML文件?

How can I parse a remote XML file?

也许我需要转换XML提取到一个DOM对象与jQuery使用。

Maybe I need to convert XML retrieved to a DOM object for use with jQuery.

推荐答案

为什么你没有在你的链接文件位置(URL:HTTP://xxx.com/yyy/mTop)的原因是becouse的网站的生产一个xml你访问该文件夹的那一刻,每次到达它的时间减慢网站..你必须做的是访问http://xxx.com/yyy/mTop您的浏览器右键 - 查看源文件code - 复制到记事本 - 另存为的.xml上传文件到另一个文件夹那么你的code URL更改为这个网址:HTTP://xxx.com/yyy/mTop/yourdailyXMLcopy XML并不断更新文件daily..else你会杀了服务器querring每个任何用户使用你的事了艰巨的工作时间...

and the reason why you dont have a file location in your link ( url: "http ://xxx.com/yyy/mTop" ) is becouse the site "produces" an xml the moment you visit the folder, slowing down the website each time you reach it..what you must do isgo to http ://xxx.com/yyy/mTop on your browserright click - view source code - copy to notepad - save as .xmlupload file to another folderthen change your code url to this url: "http ://xxx.com/yyy/mTop/yourdailyXMLcopy. xmland keep updating the file daily..else you will kill the server querring each time any user uses your thing for a huge job...

这篇关于获取远程XML文件中的AJAX和用jQuery解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:00