1

我目前正在研究 GM_getvalue 但它只将数据保存在本地存储中。我想将输入的值保存到 send.php 所在的服务器。

这是我的代码:

var $ = unsafeWindow.jQuery;

$(document).ready(function() {

    if($("#save_form").html()){
        $("#save_form").submit(function(){
            var fullname = $("#name").val();
            var IDnumber = $("#id").val();
            GM_setValue("attendancelogs",GM_getValue("attendancelogs","")+fullname+" "+IDnumber+"<br/>");
        });
    }

有人建议我使用 GM_xmlhttpRequest 但我不知道如何使用它。他告诉我 GM_xmlhttpRequest 看起来像这样:

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

最后,send.php 代码是什么?

4

1 回答 1

0

GM_xmlHttpRequest只是可以绕过SOP的XHR实现。

您可以找到XHR 的一般文档或一些示例

您当然需要将以下内容添加到脚本标题中:

// @grant GM.xmlHttpRequest

于 2020-03-16T15:26:51.023 回答