为什么这个Ajax请求在Greasemonkey中工作但在Tampermonkey中不起作用?

时间:2015-02-12 15:53:36

标签: jquery ajax greasemonkey userscripts tampermonkey

我找不到任何可以解释为什么它在Greasemonkey中工作的任何兼容性问题,而不是Tampermonkey。它似乎根本没有拉动文本文件。

function getClosings() {
    var url = "https://googledrive.com/host/0B1RCGCyAlYoJfnU3WGFERUtUUEF2V1NDY00yNWtSNWFfUkstSHJsZGNab1U5VHFnRFU5ems/vdxclosings.txt", result = "";

    jQuery.ajax({
        url: url,
        success: function(txt) {
            result = txt;
        },
        async:false
    });

    var array = parseClosingsToArray(result);
    return array;
}

function parseClosingsToArray(txt)
{
    var closings = [];
    var lines = txt.split('\n');
    for (var i=0; i<lines.length; i++)
    {
        var line = lines[i];
        line = line.replace('[', '').replace(']', ''); // remove brackets
        line = line.replace(/["']/g, "");
        line = line.replace('\n', "");

        if (line.indexOf(',') != -1)
        {
            var parts = line.split(',');        
            var code = parts[0];
            var info = parts[1];
            var row = [code, info];
            closings.push(row);
        }

    }

    return closings;
}

1 个答案:

答案 0 :(得分:0)

我不得不切换到gm_xmlhttprequest并改变一些事情。

function handleClosings() {
    GM_xmlhttpRequest({
        method: "GET",
        url: "https://googledrive.com/host/0B1RCGCyAlYoJfnU3WGFERUtUUEF2V1NDY00yNWtSNWFfUkstSHJsZGNab1U5VHFnRFU5ems/vdxclosings.txt",
        synchronous: true,
        onload: function(response) {
            result = response.responseText;
            var array = parseClosingsToArray(result);            
            modifyHtmlWithClosings(array);            
        }
    });
}