0


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

このエラーを解決する方法について何か考えはありますか?

4

1 に答える 1

0

関数 success() は存在しませんが、service() 関数があり、呼び出しsuccess() -> service()を変更するか、関数名をfunction success -> function serviceから変更します。

于 2014-09-18T08:10:06.077 に答える