[英]AJAX fails loading XML
I try to reach out to the IKEA Api to access the availability checker. 我尝试联系IKEA Api以访问可用性检查器。 If I want to ajax the file it wont return anything and the .fail function is called.
如果我想ajax该文件,它将不会返回任何内容,并且将调用.fail函数。
$('#availability').submit(function (event) {
let productNumber = $('#productId').val();
if (testString(productNumber, '^[0-9]{3}\.[0-9]{3}\.[0-9]{2}$')) {
productNumber = productNumber.replace(/\./g, '');
let target = 'http://ikea.com/de/de/iows/catalog/availability/' + productNumber;
$.ajax({
url: target,
cache: false,
dataType: 'xml'
})
.done(function (data) {
console.log('succes');
})
.fail(function (x) {
console.log(x);
});
}
event.preventDefault();
}); });
You don't see any result because your request is being blocked (here is the error that I see in the console): 您没有看到任何结果,因为您的请求被阻止了(这是我在控制台中看到的错误):
XMLHttpRequest for http://ikea.com/de/de/iows/catalog/availability/00122822/ required Cross Origin Resource Sharing (CORS). 用于http://ikea.com/de/de/iows/catalog/availability/00122822/的 XMLHttpRequest必需的跨源资源共享(CORS)。
Redirect was blocked for CORS request 重定向因CORS请求而被阻止
There are several links related to CORS error in StackOverflow. 有几个与StackOverflow中的CORS错误相关的链接。 Apparently, this is a security setting in your browser and it is unsafe to turn it off.
显然,这是浏览器中的安全设置,因此将其关闭是不安全的。
I found this link that suggests a workaround: https://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/ 我发现此链接提供了一种解决方法: https : //www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.