Search code examples
javascriptcurlspotlight-dbpedia

How to to convert my curl method to work in my javascript script?


Beginner in javascript, I'm looking for ways to convert my curl method to work in my javascript script.

Here is my curl method:

curl -X GET "http://model.dbpedia-spotlight.org/en/annotate?text=beyonce" -H "accept: text/html"

My test with ajax (doesn't work):

$.ajax({
    method: "GET",
    url: "http://model.dbpedia-spotlight.org/en/annotate?text=beyonce"
})

Solution

  • The AJAX call is missing the accept header.

    Once you add this in, it seems to work. Please see the example below:

    $.ajax({
        method: "GET",
        url: "http://model.dbpedia-spotlight.org/en/annotate?text=beyonce",
        data: { confidence: "0.60" },
        headers: {"accept" : "text/html"}
    }).done((res) => $("#res").append(res));
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="res"></div>