簡體   English   中英

通過AJAX進行API調用

[英]API call over AJAX

我是AJAX的新手,我想通過 API生成密碼。 我想使用AJAX,但不確切知道如何以及在何處指定參數。

$.ajax({
    url: 'https://passwordwolf.com/?length=10&upper=off&lower=off&special=off&exclude=012345&repeat=5',
    dataType: "text json",
    type: "POST",
    data: {upper: off, lower: on, special: off},
    success: function(jsonObject,status) {

        console.log("function() ajaxPost : " + status);

    }
});

非常感謝,請不要討厭我的編程技能!

看看他們的API:

  • 您應該使用GET方法,而不是POST
  • 網址應為https://passwordwolf.com/api/ (注意末尾的/api )。
  • 此外,passwordwolf不接受CORS,因此您應該從服務器端調用該服務,並使用適當的CORS標頭將其鏡像到前端。

請參閱下面的演示(它在任何地方都使用cors來規避CORS問題)。

它還顯示了如何正確使用對象設置參數

 var CORS = 'https://cors-anywhere.herokuapp.com/'; $.ajax({ url: CORS + 'https://passwordwolf.com/api/', dataType: "json", type: "GET", data: { length: 10, upper: "off", lower: "off", special: "off", exclude: "012345", repeat: 5 }, success: function(jsonObject, status) { console.log("ajax result: " + JSON.stringify(jsonObject)); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

暫無
暫無

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

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