weixin_33739541 2016-08-22 21:36 采纳率: 0%
浏览 9

AJAX无法加载XML

I try to reach out to the IKEA Api to access the availability checker. If I want to ajax the file it wont return anything and the .fail function is called.

$('#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();

});

  • 写回答

1条回答 默认 最新

  • weixin_33737774 2016-08-22 22:18
    关注

    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).

    Redirect was blocked for CORS request

    There are several links related to CORS error in StackOverflow. 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/

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度