Synchronization 同步GM_xmlhttpRequest异步运行?
我试图让一个Synchronization 同步GM_xmlhttpRequest异步运行?,synchronization,greasemonkey,tampermonkey,gm-xmlhttprequest,Synchronization,Greasemonkey,Tampermonkey,Gm Xmlhttprequest,我试图让一个GM\u xmlhttpRequest调用同步运行,但我无法让它像我预期的那样工作: function myFunction (arg) { var a; GM_xmlhttpRequest ( { method: "GET", url: "http://example.com/sample/url", synchronous: true, onload:
GM\u xmlhttpRequest
调用同步运行,但我无法让它像我预期的那样工作:
function myFunction (arg) {
var a;
GM_xmlhttpRequest ( {
method: "GET",
url: "http://example.com/sample/url",
synchronous: true,
onload: function (details) {
a = details.responseText;
}
} );
return a;
}
b = myFunction ();
alert (b);
我在这里从来没有为b
得到任何东西;没有定义。这里有我遗漏的步骤吗?我正在使用Greasemonkey的v0.9.13和Firefox的v9.0.1。刚刚在谷歌上偶然发现了这个话题 同步GM_xmlhttpRequest返回结果,而不是在onload回调中执行 所以这是正确的:
var details = GM_xmlhttpRequest({
method:"GET",
url:"http://site.com/sample/url",
synchronous: true
});
a = details.responseText;
您在开始时创建了var“a”,从不填充它并返回它。因此,它是未定义的。刚刚在谷歌上偶然发现了这个话题 同步GM_xmlhttpRequest返回结果,而不是在onload回调中执行 所以这是正确的:
var details = GM_xmlhttpRequest({
method:"GET",
url:"http://site.com/sample/url",
synchronous: true
});
a = details.responseText;
您在开始时创建了var“a”,从不填充它并返回它。因此,它是未定义的。是的。。。我不得不重新构造代码,因为这个“bug”不使用同步请求。使用如图所示的异步方法,或等等。。。我不得不重新构造代码,因为这个“bug”不使用同步请求。使用异步方法,如图所示,或等。