同步 GM

编程入门 行业动态 更新时间:2024-10-23 01:53:42
本文介绍了同步 GM_xmlhttpRequest 异步执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试让 GM_xmlhttpRequest 调用同步运行,但我无法让它像我期望的那样工作:

I'm trying to get a GM_xmlhttpRequest call to behave synchronously, but I can't get it to work like I expect:

function myFunction (arg) { var a; GM_xmlhttpRequest ( { method: "GET", url: "example/sample/url", synchronous: true, onload: function (details) { a = details.responseText; } } ); return a; } b = myFunction (); alert (b);

b 在这里我再也没有得到任何回报;它是未定义的.我在这里缺少一些步骤吗?我正在使用 v0.9.13 的 Greasemonkey 和 v9.0.1 的 Firefox.

I never get anything back for b here; it's undefined. Is there some step that I'm missing here? I'm using v0.9.13 of Greasemonkey, and v9.0.1 of Firefox.

推荐答案

刚刚在 Google 上偶然发现了这个话题.

Just stumbled upon this topic in Google.

同步 GM_xmlhttpRequest 返回结果,而不是在 onload-callback 中执行.

Synchronous GM_xmlhttpRequest RETURN the result instead of executing it in the onload-callback.

所以这是对的:

var details = GM_xmlhttpRequest({ method:"GET", url:"site/sample/url", synchronous: true }); a = details.responseText;

您在开始时创建了 var "a",从不填充它并返回它.因此,它是未定义的.

You create the var "a" in the beginning, never fill it and return it. Therefore, it is undefined.

更多推荐

同步 GM

本文发布于:2023-11-24 23:07:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627260.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:GM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!