Synchronous GM_xmlhttpRequest acting asynchronously?

后端 未结 1 1668
失恋的感觉
失恋的感觉 2020-12-07 04:02

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) {
             


        
相关标签:
1条回答
  • 2020-12-07 04:23

    Just stumbled upon this topic in Google.

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

    So this would be right:

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

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

    0 讨论(0)
提交回复
热议问题