-1

I've been working with the codes involving GM_getvalue and GM_setValue. I'd like to access data in my server through ajax.

I've been working with the codes involving GM_getvalue and GM_setValue. Stored data can be found in Storage located in Tampermonkey>Dashboard>Script>Storage. However, it could only be seen on one PC. I would like to access the data in my website/server. Are there any suggestions and codes to make it possible? Ajax perhaps?

if($("#name_full").html()){
    $("#name_full").submit(function(){
        var Fname = $("#firstname").val();
        var Sname = $("#surname").val();
        GM_setValue("datalogs",GM_getValue("name_full","")+Fname+" "+Sname +"<br/>");
    });
}

I expect codes that can help me obtain these data via my website/server. Help :(

  • `localStorage` is just that: *local*. It is meant to exist only for the browser where the code ran, and it's up to the browser how long it keeps it around. It cannot be accessed by the server. You would have send the values from `localStorage` to the server (AJAX is one option) and persist it there using session/DB/something else. If you are moving from cookies to `localStorage`, this is one major difference -- that data is not attached to a request to/from the server. – Cᴏʀʏ Apr 10 '19 at 02:19

1 Answers1

0

localStorage is the kind of browser storage. It means server can't see what data is stored. If you want to send data from localstorage to the server, you should use http request method. You can use GM_xmlhttpRequest method. For example, code can be like this.

jQ(document).on("keyup", "form input", function () {
    let value = GM_getValue("name_full","");
    GM_xmlhttpRequest({
        method: "POST",
        url: "http://....",
        data: value,
        headers: {
            "Content-Type": "application/x-www-form-urlencoded"
        },
        onload: function(response) {
            alert(response);
            var json = $.parseJSON(response); 
        }
    });

});

Liko
  • 16