代码:
// ==UserScript==
// @name testpost
// @namespace http://tampermonkey.net/
// @version 2024-04-06
// @description try to take over the world!
// @author You
// @match http://localhost:5184/
// @icon https://www.google.com/s2/favicons?sz=64&domain=undefined.localhost
// @grant GM_xmlhttpRequest
// @connect localhost
// @grant none
// ==/UserScript==
(function() {
'use strict';
console.log("now post");
var jdata= {id:100,name:'yyyyyyyyyyyyyyp'};
GM_xmlhttpRequest({
url:"http://localhost:5184/pizzas",
dataType: "json",
method :"POST",
data:"{\"id\":100,\"name\":\"yyyyyyyyyyyyyyp\"}",
headers: {
"Content-type": "application/json"
},
onload:function(xhr){
console.log(xhr.responseText);
}
});
})();
出错为: