1

我正在尝试在 phonegap 应用程序中使用 jquery 从外部 url 获取值。

但这不起作用,这是我的代码:

<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.6.2.min.js">
</script>
<script>
$(document).ready(function(){
    jQuery.support.cors = true;
    $("button").click(function(){
$.ajax({
        type: "GET",
        url: "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('Cube').each(function(){

                var usd = $(this).find('Cube type=["currency"]').text();


                $("#d").html(usd);

            });
        }
    });
});

});
</script>
</head>
<body>

<div id="d"></div>
<button>Get External Content</button>

</body>
</html>

有什么方法可以使用以下方法从/向外部 url 加载/发布/获取数据:

phonegap,jquery,jquerymobile,.......?

4

1 回答 1

1

您可以使用您的 url 而不是 xml 文件。因为我从浏览器尝试过,所以我创建了 xml 文件。

 $.ajax({
            type: "GET",
            url: "../res/exData.xml",
            dataType: "xml",
            success: function (xml){    

                $(xml).find('Cube').each(function(){
                    $.each(this.attributes, function(i, attrib){
                         var name = attrib.name;
                         var value = attrib.value;
                         if (name === "currency")
                            $("#d").html(value);
                    });
                 });        

            }, 
            error: function(model, xhr, options) { 
                alert("error");
            }
        });
于 2013-09-12T09:14:34.073 回答