簡體   English   中英

我可以針對此API使用jquery的ajax方法而非unirest嗎?

[英]Can I use jquery's ajax method instead of unirest for this API?

這是我要使用的API的說明。 它建議使用unirest,但我無法在服務器上安裝節點。

https://www.wordsapi.com/docs/?javascript#

這是我要使用的代碼:

$(document).ready(function() {
    $.ajax({
        url: "https://wordsapiv1.p.mashape.com/words/soliloquy",
        type: "GET",
        datatype: "json",
        crossDomain: "true",
        contentType: "application/json; charset=utf-8",
        headers: {"X-Mashape-Key": "XXXXXXX"},
        success: function(result) {
            alert("SUCCESS!");
        },
        error: function(result) {
            alert("FAIL!");
        }
    });
});

但我收到該請求的401未經授權的結果。 X-Mashape-Key標頭包含在使用我的api鍵的調用中,但似乎不想接受它。 unirest會執行此jquery ajax調用不執行的操作嗎?

試試看

beforeSend: function (xhr) {
   xhr.setRequestHeader ("Authorization", "Basic " + btoa(Your X-Mashape-Key));
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM