无法从GM_xmlhttpRequest

时间:2020-05-05 05:56:55

标签: tampermonkey userscripts gm-xmlhttprequest

我有从站点获取一些数据的脚本。我是新手,无法找到方法。现在,我仅在tampermonkey上使用xmlhttpRequest,并且可以轻松定义任何变量。我应该用它构造还是用GM_xmlhttpRequest代替。 元区块:

// ==UserScript==
// @name name
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description enter something useful
// @match   http*://*
// @grant        GM_xmlhttpRequest
// @grant        GM_download
// @copyright 2012+, You
// ==/UserScript==

这是我的代码:

GM_xmlhttpRequest ( {
method: "GET",
url:  "https://some.url/to.json",
responseType: "json", 
onload: processJSON_Response

} );
function processJSON_Response (json) {alert("defining json");
var b = JSONparse(json.response)
window.a=b.name

}
alert(a)

有没有保存和使用变量的方法(无论在函数之前还是在Gm之后)。我将在GM_xmlhttpRequest之后不只使用一次响应文本

0 个答案:

没有答案