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:未定义成功

关于如何解决这个错误的任何想法?

4

1 回答 1

0

函数 success() 不存在,但是您有一个 service() 函数,您可以更改调用success() -> service()或者从function success -> function service更改函数名称

于 2014-09-18T08:10:06.077 回答