Greasy Fork is available in English.

Discussioni » Sviluppo

Greasemoneky GM_xmlhttpRequest POST

§
Pubblicato: 29/07/2016

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;
}
});

woxxomMod
§
Pubblicato: 29/07/2016

Typo: paramter

§
Pubblicato: 29/07/2016

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

§
Pubblicato: 29/07/2016
Modificato: 29/07/2016

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;
    }
});
§
Pubblicato: 30/07/2016

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.

Pubblica risposta

Accedi per pubblicare una risposta.