我正在嘗試向維基百科發出幾個Ajax請求。 Ajax調用位於for-loop(JavaScript)中,這是一個問題,因爲它們不按順序返回。爲了解決這個問題,我想我會在Ajax請求中包含一個請求ID,就像他們的沙盒中的一個選項一樣。問題是ID不會返回...?Wikipedia api不返回請求ID
(來自維基的sandbox)
https://en.wikipedia.org/wiki/Special%3aApiSandbox#action=opensearch&format=json&requestid=12&search=clownfish
回報:
[
"clownfish",
[
"Clownfish",
"Clown"
],
[
"To the scientific name of an organism: This is a redirect from a vernacular (\"common\") name to the scientific name of an organism (or group of organisms).",
"Clowns are comic performers who employ slapstick or similar types of physical comedy, often in a mime style."
],
[
"https://en.wikipedia.org/wiki/Clownfish",
"https://en.wikipedia.org/wiki/Clown"
]
]
沒有的requestId。但是,當我將操作從「opensearch」更改爲其他內容時,它確實會返回請求標識。
https://en.wikipedia.org/wiki/Special%3aApiSandbox#action=cspreport&format=json&requestid=12
回報:
{
"error": {
"code": "cspreport-wrongformat",
"info": "Error processing CSP report: wrongformat.",
"*": "See https://en.wikipedia.org/w/api.php for API usage."
},
"requestid": "12",
"servedby": "mw1194"
}
正如你所看到的,這種反應不包括的requestId。
這是預期的行爲,還是我錯過了什麼?任何幫助,非常感謝:)
我無法在API文檔中找到'requestid'參數的文檔。你有鏈接到描述它的頁面嗎? – Barmar
對不起,我沒有任何文檔,除了它在沙箱中提到的內容(鏈接問題),它說:「此處給出的任何值都將包含在響應中,可用於區分請求。 」。我只是不明白爲什麼它不應該包含在開放式搜索中?有任何想法嗎? – user2267097
非常基本上解釋了[這裏](https://www.mediawiki.org/wiki/API:Main_module),它說:「requestid:這裏給出的任何值都會包含在響應中,可以用來區分請求。1.14+「 – user2267097