ajax、javascript を使用して mashape API を使用しようとしています。
HTML にテキスト領域とボタンがあります。
<div>
<textarea id="message" placeholder="Message">
</textarea>
<br><br>
<button id="mb" onclick="success();">Analyse</button>
</div>
そして、本当に単純な JavaScript の success() 関数:
function service(){
$.ajax({
url: 'https://loudelement-free-natural-language-processing-service.p.mashape.com/nlp-text/', // The URL to the API. You can get this by clicking on "Show CURL example" from an API profile
type: 'GET', // The HTTP Method
data: {text: $("#m").val()}, // Parameters go here
datatype: 'json',
success: function (data) {
alert(data);
},
error: function (err) {
alert(err);
},
beforeSend: function (xhr) {
xhr.setRequestHeader("X-Mashape-Authorization", "<MY MASHAPE KEY>"); // Enter your Mashape key here
}
});
};
ただし、関数をトリガーすると、ブラウザーコンソールに次のエラーが表示されます: ReferenceError: success is not defined
このエラーを解決する方法について何か考えはありますか?