尝试使用javascript使用Mashape Web服务时出错

Error while trying to consume a Mashape webservices using javascript

本文关键字:Web 服务 出错 Mashape 使用 javascript      更新时间:2023-09-26


我正在尝试使用ajax、javascript来使用一个mashupapi。

我的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()不存在,但是您有一个服务()函数,您可以更改调用success