0

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"
})
Miley
  • 19
  • 4

2 Answers2

1

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>
user184994
  • 17,791
  • 1
  • 46
  • 52
1

I'd recommend using the fetch API over this jquery ajax method you're using. It's quite supported

fetch("http://model.dbpedia-spotlight.org/en/annotate?text=beyonce").then(response => response.text())

If you consider using it, I'd also recommend learning how to deal with Promises in case you don't know!