Search code examples
javascriptjqueryhtmlajaxodata

Jquery .ajax get request with Odata


I am facing the following problem, I am trying to build a small application to search within the Odata dataset from the KVK (dutch chamber of commerce) to retrieve data based on file numbers, ZIP codes or tradenames.

My ajax code looks like this:

        $.ajax({
        url: urls,
        error: function(){console.log('FAILED!')},
        headers: 
        {
            "Content-Type":"application/json",
            "ovio-api-key":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
        },
        dataType: 'jsonp',
        complete: function(data) {
            console.log(data);
        }
    });

the URL would like like this:

https://overheid.io/api/kvk?&filters[postcode]=3553BA&callback=jQuery110208921047365292907_1432134770039&_=1432134770040

The error I am getting:

enter image description here

The part I do not understand, when I try the exact same URL in a web rest client such as chrome's advanced rest client the result is exactly what I want:

enter image description here


Solution

  • Fixed this by changing the code to:

                    $.ajax({
            type: 'GET',
            url: urls,
            error: function(){console.log('Gefaald!')},
            headers: 
            {
                "Content-Type":"application/json",
                "ovio-api-key":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
            },
            dataType: 'json',
            complete: function(data) {
                console.log(data);
            }
        });
    

    just had to add the 'GET' type.