1
我在Netbeans 8.0.2中创建了一个HTML5 Cordova应用程序。因为我试图从提供货币转换器的网站webservicex.net使用REST API,例如http://www.webservicex.net//CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&ToCurrency=INR。在Netbeans 8.0.2中Cordova应用程序的CORS问题
当我试图在我的Javascript代码中调用这个RESTful Webservice时,它会在我的控制台上显示一条错误消息,如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());
});
});
});
指定的URL在浏览器上工作正常,甚至我尝试使用简单的http://www.google.com仍显示相同的错误。 –