Вопрос:

AJAX fails loading XML

javascript jquery ajax xml

55 просмотра

1 ответ

0 Репутация автора

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();

});

Автор: user5423851 Источник Размещён: 22.08.2016 09:36

Ответы (1)


0 плюса

2067 Репутация автора

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/

Автор: Sparrow Размещён: 22.08.2016 10:18
Вопросы из категории :
32x32