【问题标题】:CORS Issue for Cordova Application in Netbeans 8.0.2Netbeans 8.0.2 中 Cordova 应用程序的 CORS 问题
【发布时间】:2015-09-02 17:45:39
【问题描述】:

我在 Netbeans 8.0.2 中创建了一个 HTML5 Cordova 应用程序。我正在尝试从提供货币转换器的网站 webservicex.net 使用 REST API,即http://www.webservicex.net//CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=INR

当我尝试在我的 Javascript 代码中调用此 RESTful Web 服务时,它会在我的控制台上显示一条错误消息,例如 CROS 域问题。

这是我的代码 javascript 代码。

 $(document).ready(function() {
            $("#btn").click(function() {
                $.ajax({
                    url:'http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=INR',
                    type: 'get',
                    crossDomain: true,
                    ContentType: 'xml',
                    dataType: 'text',
                    cache: false
                    }).done(function(response) {
                    var str = response;
                    alert(str);
                    var xmlDoc = $.parseXML(str);
                    var $xml = $(xmlDoc);
                    var $Name = $xml.find('double');
                 alert(parseFloat($Name.text())+10);
                 var $a = parseFloat($Name.text())+10;
                    $('span').html($Name);
                    $("#displayout").html($a);
                }).fail(function(request, textStatus, errorThrown) {

                    alert("error, fail");

                    alert(textStatus + " : " + errorThrown.toString());
                });
            });
        });

【问题讨论】:

    标签: javascript html ajax netbeans cors


    【解决方案1】:

    您确定为 URL 参数使用了正确的端点吗?您指定的网址似乎没有配置 CORS 标头,因此您将无法从外部站点访问它。

    【讨论】:

    • 指定的 URL 在浏览器上运行良好,即使我尝试使用简单的 google.com 仍然显示相同的 cors 错误。
    猜你喜欢
    • 1970-01-01
    • 2016-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-17
    • 1970-01-01
    相关资源
    最近更新 更多