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仍顯示相同的錯誤。 –