讨论 » 开发

Greasemoneky GM_xmlhttpRequest POST

§
发表于:2016-07-29

Greasemoneky GM_xmlhttpRequest POST


I am trying to create a script that will send a POST requests immediately after loading the web page .

The POST data parameter will contain certain values that it will collect from element in responseHTML via "document.getElementsByName"

here is what i am doing but it isnt working ---

var id1 = document.getElementsByName("ID1")[0].value

var id2 = document.getElementsByName("ID2")[0].value

GM_xmlhttpRequest({method: "POST",
url: "https://www.example.com/",
data: 'paramter1=' + id1 '¶mter2=' + id2 ,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
onload: function(response) {
console.log ("gut response");
$("#input").get()[0].value=response.responseText;
}
});

woxxom管理员
§
发表于:2016-07-29

Typo: paramter

§
发表于:2016-07-29

xmlhttpRequest works only on same domain I think.
Are you pushing your script in a page from example.com?

§
发表于:2016-07-29
编辑于:2016-07-29

For reference, the code indented and as a code block:

var id1 = document.getElementsByName("ID1")[0].value

var id2 = document.getElementsByName("ID2")[0].value

GM_xmlhttpRequest({
    method: "POST",
    url: "https://www.example.com/",
    data: 'paramter1=' + id1 '&paramter2=' + id2,
    headers: {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    onload: function(response) {
        console.log("gut response");
        $("#input").get()[0].value = response.responseText;
    }
});
§
发表于:2016-07-30

I assume you don't see any obvious errors in the console?

Try adding an onerror handler to see whether you get any insight that way.

发表回复

登录以发表回复。