Netbeans 8.0.2 中 Cordova 应用程序的 CORS 问题

CORS Issue for Cordova Application in Netbeans 8.0.2

本文关键字:应用程序 CORS 问题 Cordova Netbeans      更新时间:2023-09-26

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

当我尝试在我的Javascript代码中调用这个RESTful Web服务时,它将在我的控制台上显示一条错误消息,如CROS Domain Problem。

这是我的代码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());
                });
            });
        });
是否确定为

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